grouping →
cube() → grouping

Expands a grouping into all combinations of retained and aggregated dimensions.

Parameters

This function has no parameters.

Argument evaluation

Visits each group of the grouping supplied as pipeline input to this cube call in source order for each subset of dimensions, including empty groups. Existing keys determine dimensions; grouped values are copied without evaluating expressions against them.

Behavior

Generates all 2^N grouping levels for N dimensions, starting with the original level and ending with the grand total. Levels follow binary mask order, with the rightmost dimension changing fastest: for two dimensions, (a, b), (a, #all), (#all, b), then (#all, #all). The number of levels grows exponentially with the number of dimensions. Within each level, keys retain first-seen order and values concatenate in source-group order, including duplicates, nulls and empty groups. Values are never aggregated; compose with summarize to calculate totals.

For two dimensions, the equivalent explicit pattern is grouping-sets(T(0, 1), tuple(0), tuple(1), tuple()).

Uses the same AllDimension.Instance marker as roll-up, whose source literal is #all and which is distinct from null and the string “#all”. Reading #all represents an already-aggregated dimension; it does not aggregate values or act as a wildcard. Scalar keys have one dimension and a scalar total key; arrays and records are scalar dimensions. Tuple arity is retained, with nested tuples treated as single dimensions. Empty groupings remain empty; zero-component tuples have only their original level. All keys must be scalar or all tuples of the same arity. Mixed shapes and keys already containing the aggregated marker as a dimension fail with an argument error, preventing ambiguous dimensions and double-counting.

Examples

#{(T("BE", 2025) => {120, 30}), (T("FR", 2025) => {90}), (T("BE", 2026) => {80})} | cube | summarize(sum) | map(pair-value)  {150, 90, 80, 230, 90, 240, 80, 320}

Kind: Function
Scope: grouping
Aliases: None


This site uses Just the Docs, a documentation theme for Jekyll.