Group By Cube
| AVAILABLE API VERSION |
|---|
| API v58.0 and later |
The CUBE type adds subtotals for all combinations of a grouped field in the query result. This group by type enables you to create a query to calculate a sum, an average, or another aggregate function. You can then group the results by a horizontal set of values and a vertical set of values.
Use CUBE with aggregate functions, such as sum and count.
If you want only subtotals for a subset of the grouped field combinations, use groupBy with ROLLUP type instead.
Aggregate Results with Group By Cube
To aggregate results using group by cube, use the following syntax. Replace objectApiName with the object’s API name, like Account. Field1 and Field2 represent fields on the object, like Industry and AnnualRevenue.
1query rollupExample {
2 uiapi {
3 aggregate {
4 objectApiName (groupBy: { type: CUBE, Field1: { group: true }, Field2: { group: true } }) {
5 edges {
6 node {
7 aggregate {
8 _Field1_ {
9 value
10 grouping {
11 value
12 }
13 }
14 _Field2_ {
15 value
16 grouping {
17 value
18 }
19 }
20 // Other optional fields
21 }
22 }
23 }
24 }
25 }
26}A query with the CUBE type can include up to three fields in a comma-separated list in the groupBy argument clause.
Note
See Also
SOQL and SOSL Reference: GROUP BY CUBE