OLAP Aggregate Queries : Grouping Parameter : Multi-level Grouping

Multi-level Grouping
The grouping parameter can list multiple grouping expressions to form multi-level grouping. Each grouping expression must be a path from the perspective table to a link or scalar field. Below is an example multi-level aggregate query:
GET /Email/Message/_aggregate?m=COUNT(*)&f=TRUNCATE(SendDate,DAY),Tags&range=0
In this example, TRUNCATE(SendDate,DAY) is the top-level grouping field and Tags is the second-level grouping field. The query creates groups based on the cross-product of all grouping field values, and a metric is computed for each combination for which at least one object has a value. A perspective object is included in the metric computation for each group for which it has actual values. A summary value is computed for each non-leaf group, and a totalobjects value is computed for the top-level group. An example result in XML is shown below:
<results>
<aggregate metric="COUNT(*)" group="TRUNCATE(SendDate,DAY),Tags"/>
<totalobjects>6030</totalobjects>
<summary>6030</summary>
<groups>
<group>
<summary>4752</summary>
<field name="SendDate">2010-07-17 00:00:00</field>
<groups>
<group>
<metric>1</metric>
<field name="Tags">(null)</field>
</group>
<group>
<metric>4751</metric>
<field name="Tags">AfterHours</field>
</group>
<group>
<metric>1524</metric>
<field name="Tags">Customer</field>
</group>
</groups>
</group>
<group>
<summary>1278</summary>
<field name="SendDate">2010-07-18 00:00:00</field>
<groups>
<group>
<metric>1278</metric>
<field name="Tags">AfterHours</field>
</group>
<group>
<metric>700</metric>
<field name="Tags">Customer</field>
</group>
</groups>
</group>
</groups>
</results>
The same response in JSON:
{"results": {
"aggregate": {"metric": "COUNT(*)", "group": "TRUNCATE(SendDate,DAY),Tags"},
"totalobjects": "6030",
"summary": "6030",
"groups": [
{"group": {
"summary": "4752",
"field": {"SendDate":"2010-07-17 00:00:00"},
"groups": [
{"group": {
"metric": "1",
"field": {"Tags": "(null)"}
}},
{"group": {
"metric": "4751",
"field": {"Tags":"AfterHours"}
}},
{"group": {
"metric": "1524",
"field": {"Tags":"Customer"}
}}
]
}},
{"group": {
"summary": "1278",
"field": {"SendDate": "2010-07-18 00:00:00"},
"groups": [
{"group": {
"metric": "1278",
"field": {"Tags":"AfterHours"}
}},
{"group": {
"metric": "700",
"field": {"Tags":"Customer"}
}}
]
}}
]
}}
Each non-leaf group has an inner groups element containing its corresponding lower-level group elements and a summary element that provides a group-level metric value. Leaf-level groups have a metric element. This structure is recursive if there are more than two grouping levels.