---
schema_version: "1"
id: d5e4ebb4599c7732d589f0f71c28be457dadb32fad4854526ffbaceb9c97bf20
title: Group By Cube
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/graphql-api/graphql/guides/aggregate/aggregate-groupby-cube.md
canonical_url: https://developer.salesforce.com/docs/platform/graphql/guide/aggregate-groupby-cube.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 02681f867da4e995206238ae42be5c342506a3c070900fadaaa47a447606a6d4
products:
  - GraphQL API
---
# 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](https://developer.salesforce.com/docs/platform/graphql/guide/aggregate-support.md), such as `sum` and `count`.

If you want only subtotals for a subset of the grouped field combinations, use [`groupBy` with `ROLLUP` type](https://developer.salesforce.com/docs/platform/graphql/guide/aggregate-groupby-rollup.md) 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.

```
query rollupExample {
  uiapi {
    aggregate {
      objectApiName (groupBy: { type: CUBE, Field1: { group: true }, Field2: { group: true } }) {
        edges {
          node {
            aggregate {
              _Field1_ {
                value
                grouping {
                  value
                }
              }
              _Field2_ {
                value
                grouping {
                  value
                }
              }
              // Other optional fields
             }
          }
        }
    }
  }
}
```

**note:** A query with the `CUBE` type can include up to three fields in a comma-separated list in the `groupBy` argument clause.

## See Also

[SOQL and SOSL Reference: GROUP BY CUBE](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_groupby_cube.htm)
