OpenBI Docs Buy

GROUPBY

A table's rows grouped by columns, with columns computed over each group's rows (CURRENTGROUP), without context transition.

Group: Table manipulation. Compatible with DAX.

Syntax

GROUPBY ( <table> [, <groupBy_columnName>] … [, <name>, <expression>] … )
ParameterTypeDescription
tableTableThe rows to group: a table of the model or any table expression, such as a variable.
groupBy_columnNameColumn
optional, repeatable
A column to group by: one of the table's, or of a table it reaches through relationships.
nameText
optional, repeatable
The name of a new column, in quotes.
expressionExpression
optional, repeatable
An aggregation over CURRENTGROUP (), worked out for each group.

Returns

Table. One row per combination of the grouping columns' values, with the new columns.

Remarks

  • Each expression reaches the group's rows through CURRENTGROUP (), inside an X function such as SUMX or MAXX. DAX allows nothing else in these expressions.
  • There is no context transition, so a measure would not see the group. That sets GROUPBY apart from SUMMARIZE, and suits it to tables made in the query, whose columns have no tie to the model.
  • Without a grouping column, all rows make one group and the result has one row; an empty table gives none.
  • Grouping columns may come from related tables: GROUPBY ( Sales, Products[Category], ... ).
  • A blank is a value of its own when rows are grouped.

Examples

Liters by shop and product

EVALUATE
VAR Sold =
    DATATABLE (
        "Shop", STRING, "Product", STRING, "Liters", INTEGER,
        { { "A", "Pils", 10 }, { "A", "IPA", 5 }, { "B", "Pils", 7 }, { "B", "Pils", 3 } }
    )
RETURN
    GROUPBY ( Sold, [Shop], [Product], "Liters", SUMX ( CURRENTGROUP (), [Liters] ) )
ORDER BY [Shop], [Product]
ShopProductLiters
AIPA5
APils10
BPils10

Grouping by a column of a related table

EVALUATE
GROUPBY ( Sales, Products[Category], "Liters", SUMX ( CURRENTGROUP (), Sales[Liters] ) )
ORDER BY Products[Category]
Products[Category]Liters
Beer1505389
Cider301074

No grouping column

All four rows form one group.

EVALUATE
VAR Sold =
    DATATABLE (
        "Shop", STRING, "Product", STRING, "Liters", INTEGER,
        { { "A", "Pils", 10 }, { "A", "IPA", 5 }, { "B", "Pils", 7 }, { "B", "Pils", 3 } }
    )
RETURN
    GROUPBY ( Sold, "Liters", SUMX ( CURRENTGROUP (), [Liters] ) )
Liters
25

CURRENTGROUP, SUMMARIZE, SUMMARIZECOLUMNS, SUMX, ADDCOLUMNS.

Last updated · OpenBI Studio 0.3.74