GROUPBY (<table>, , … )
Tutorial with example
In today’s DAX Fridays, we will go through the DAX function GROUPBY with an example.
GROUPBY is similar as SUMMARIZE, but the difference is that in the expression part, you use DAX iterators to get your results.
You can also nest GROUPBY functions to get for example the highest sales amount by country.
Download example file:
- The GROUPBY function does the following:
- Start with the specified table (and all related tables in the “to-one” direction).
- Create a grouping using all of the GroupBy columns (which are required to exist in the table from step #1.).
- Each group is one row in the result, but represents a set of rows in the original table.
- 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.