On going through the Datadog aggregation methods and space aggregation documents, it can be seen that they support group by aggregation in the queries for metrics.
In this case it is using sum by
in the following way:
sum:orders{status:failed} by{category}.as_count()
One can refer the Datadog nested queries multilayer space aggregation for more examples.