GROUPBY DAX Function in Power BI

The GROUPBY function in Power BI is a DAX function used to group rows in a table by specified columns. It allows us to aggregate data without needing to create a physical grouping in the data model, and we can create calculated tables or summarize data on the fly.

DAX Syntax GROUPBY (table [, groupBy_columnName [, groupBy_columnName [, …]]] [, name, expression [, name, expression [, …]]])

The function has the following parameters:

Example: Let’s create a calculated table.

DAX

Countries Average Table = 
CALCULATETABLE (
    GROUPBY (
        Countries,
        Countries[Country],
        "AvgValue", AVERAGEX ( CURRENTGROUP (), Countries[Literacy Rate (%)] )
    )
) 

The output of the above dax function is shown below:

GROUPBY dax function in Power BI

Let’s create a calculated table, apply the filters to remove the Literacy Rate (%) have the 0 values.

DAX

Countries Average Table = 
CALCULATETABLE (
    GROUPBY (
        Countries,
        Countries[Country],
        "AvgValue", AVERAGEX ( CURRENTGROUP (), Countries[Literacy Rate (%)] )
    ),
    Countries[Literacy Rate (%)] <> 0
)

The output of the above dax function is shown below:

GROUPBY dax function in Power BI

DAX

Countries Average Measure = 
AVERAGEX (
    CALCULATETABLE (
        GROUPBY (
            Countries,
            Countries[Country],
            "AvgValue", AVERAGEX ( CURRENTGROUP (), Countries[Literacy Rate (%)] )
        ),
        Countries[Literacy Rate (%)] <> 0
    ),
    [AvgValue]
)

The output of the above dax function is shown below:

GROUPBY dax function in Power BI