Power BI GroupBy

Group by is a type of query which is also used in power bi, there is an editor in power bi which is known as query editor window which has various queries for accessing data and such query is Group by which is used to group rows based on a given certain value.

Group By Function in Power BI

Power BI GROUPBY Dax Function will group together data by collecting the information from two different tables. This works almost similar to the summarized function in Power BI, but groupby doesn’t allow us to do any kind of implicit calculations by using the calculate function; instead, it allows us to use the new DAX function “CURRENTGROUP()” inside the aggregation functions in the additional column it adds.

Below is the SYNTAX of the Power BI GROUP BY Dax function.

Power BI Group By Syntax
  • <Table>: First, we need to specify the table name from where we are grouping the data.
  • [<GroupBy_columnName1>]: What is the relationship first column from any of the two tables?
  • [<GroupBy_columnName2>]: What is the relationship second column from any of the two tables?
  • <Name>: This will be what is the name for the new column we are going to create.
  • <Expression>: By using which DAX function, we need to aggregate the values.

I know it is not that easy to understand by reading the syntax explanations, but in the example sections, you will learn clearly.


You are free to use this image on your website, templates etc, Please provide us with an attribution linkHow to Provide Attribution?Article Link to be Hyperlinked
For eg:
Source: Power BI GroupBy (wallstreetmojo.com)

How to Use GroupBy Dax Function in Power BI?

To use the Power BI groupby function, we need at least two tables, and below are the two tables I am going to use it for this DAX function demonstration.

Excel Data

Between the first table (Sales Table) and the second table (Buyers Table), the common column is “Category.” In the “Buyers” table, we have what is the category for each buyer, so using these two tables, we will group the data.

While grouping the data, we need to identify what are the columns we need in the new group table; in this case, I need “Category, Buyer, Sale Value, and Cost Value.”

Copy and paste the data directly to Power BI, or you can copy the data to an excel file and then import it to Power BI as an Excel file reference. So you can download the excel workbook template from the below link, which is used for this example.

You can download this Power BI GroupBy Excel Template here – Power BI GroupBy Excel Template

I have directly uploaded the data to Power BI.

Imported Data

Since we are grouping the data, we need to store it as a new table.

Follow the steps to use Group By Dax function in Power BI.

  1. In Power BI, go to “Modelling” and click on “New Table.”

    Power BI Group By - Enter New Table

  2. This will create a new table, and in the formula bar, we can see it has highlighted the same.

    Power BI Group By - New Table

  3. First, give a name to this new table as “Group by Category u0026 Buyer.”

    Power BI Group By - Change Table Name

  4. After the table name, put equal sing and open Power BI GROUPBY DAX function.

    Power BI Group By - Insert Group By Function

  5. The first argument of power bi GROUPBY DAX function is Table i.e., out of available two tables from which table we need to group the data, in this example, we need to group the data from the “Sales” table, so supply the table name as “Sales.”

    Power BI Group By - Agrument 1

  6. The next argument is GroupBy_ColumnName1 i.e., based on which column we need to group the data. So from “Sales Table,” we need to group by “Category-wise,” so select the “Category” column from “Sales Table.”

    Power BI Group By - Agrument 2

  7. Next, from the “Buyers” table, we need to mention the column name to be grouped. So from the “Buyers” table, we need to group by “Buyers-wise.”

    Power BI Group By - Column To be Grouped

  8. Ok, specifying column names is over. Next we need to give a name to the aggregate column. Since we are aggregating the “Sale Value” column, we will give the same name only.

    Power BI Group By - Aggregate Column Name

  9. Next, for this new “Sales Value” column, we need to apply the DAX function to return the aggregate value. Open SUMX function in the Expression 1 argument.

    Power BI Group By - SUMX Function

  10. For this expression, we need to supply a special CURRENTGROUP() function.

    Power BI Group By - Currentgroup Function

    Note: CURRENTGROUP() function can be used inside the Power BI GroupBy function only. This function access to the sub-table representing the current group in GROUPBY function.

  11. In the next argument of SUMX function, open SUM functionOpen SUM FunctionThe SUM function in excel adds the numerical values in a range of cells. It is categorized under the math and trigonometry function entered by typing “=SUM” followed by the values to be summed. The values can be numbers, cell references or ranges.read more.

    Power BI Group By - SUM Function

  12. Since we are adding the “Sales Value” column from the “Sales” table, enter the column name. After this, close two brackets for SUMX u0026 SUM functions and enter a comma.

    Power BI Group By - SUM (Table Name)

  13. Name 2 is the argument of GROUPBY function i.e., what the name of the second aggregate column is, enter the name as “Cost Value” in double-quotes.

    Power BI Group By - 2nd Aggregate Column Name

  14. For this also open SUMX function, inside this open CURRENTGROUP function and for Expression open SUM function and choose the “Cost Value” column from the “Sales” table.

    Power BI Group By

  15. Now close three brackets for Power BI SUMXPower BI SUMXSUMX is a function in power BI which returns the sum of expression from a table. It is an inbuilt mathematical function. The syntax used for this function is SUMX(,).read more, SUM, and GROUPBY functions and hit the enter key to close the DAX formula. Then you can see three tables here. Select the newly created table for grouping. In this; we can see DAX expression in the formula section.

    Power BI Group By - Result

    As you can see above, we can see the aggregated grouped table.

    Note: I have done so much of formatting to this table, you can download the Power BI RANKX Template from the below link and apply each formatting technique as applied.

    You can download this Power BI GroupBy Template here – Power BI GroupBy Template

    Things to Remember

    This has been a guide to Power BI GroupBy. Here we discuss how to group together the data by collecting the information from two different tables using Power BI GROUPBY DAX function. You can learn more from the following articles –

    • 6 Online Courses
    • 29+ Hours
    • Verifiable Certificate of Completion
    • Lifetime Access
    Saturday - Sunday 9 am IST to 5 pm IST
    Saturday - Sunday 9 am IST to 5 pm IST