GROUPBY

Updated on

GROUPBY is a DAX function that creates a summary table grouped by specified columns.

Syntax

GROUPBY(
   Table,
   [ GroupBy_ColumnName, ... ],
   [ Name, ... ],
   [ Expression, ... ]
)
Argument Properties Description
Table The input table.
GroupBy_ColumnName Optional, Repeatable A column to group by.
Name Optional, Repeatable A column name to be added.
Expression Optional, Repeatable The expression of the new column.

Return Values

A table with the selected columns for the groupBy_columnName arguments and the extension columns designated by the name arguments.

Remarks

  • The GROUPBY function does the following:

    1. Start with the specified table (and all related tables in the “to-one” direction).

    2. Create a grouping using all of the GroupBy columns (which are required to exist in the table from step #1.).

    3. Each group is one row in the result, but represents a set of rows in the original table.

    4. For each group, evaluate the extension columns being added. Unlike the SUMMARIZE function, an implied CALCULATE is not performed, and the group isn’t placed into the filter context.

  • Each column for which you define a name must have a corresponding expression; otherwise, an error is returned. The first argument, name, defines the name of the column in the results. The second argument, expression, defines the calculation performed to obtain the value for each row in that column.

  • groupBy_columnName must be either in table or in a related table.

  • Each name must be enclosed in double quotation marks.

  • The function groups a selected set of rows into a set of summary rows by the values of one or more groupBy_columnName columns. One row is returned for each group.

  • GROUPBY is primarily used to perform aggregations over intermediate results from DAX table expressions. For efficient aggregations over physical tables in the model, consider using SUMMARIZECOLUMNS or SUMMARIZE function.

  • This function is not supported for use in DirectQuery mode when used in calculated columns or row-level security (RLS) rules.

With CURRENTGROUP

CURRENTGROUP can only be used in an expression that defines an extension column within the GROUPBY function. In-effect, CURRENTGROUP returns a set of rows from the table argument of GROUPBY that belong to the current row of the GROUPBY result. The CURRENTGROUP function takes no arguments and is only supported as the first argument to one of the following aggregation functions: AVERAGEX, COUNTAX, COUNTX, GEOMEANX, MAXX, MINX, PRODUCTX, STDEVX.S, STDEVX.P, SUMX, VARX.S, VARX.P.

Empty

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/groupby-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy