Power BI DAX: SUMMARIZE Multiple Columns
YearlySalesByRegion =
SUMMARIZE(
Sales,
'Date'[Year],
Sales[Region],
"Total Sales", SUM(Sales[Sale])
)
The SUMMARIZE function in DAX is a versatile tool for creating summary tables by grouping data based on multiple columns. This function allows users to aggregate data efficiently, providing insights into various combinations of categories.
Example Scenario
Imagine you have the following data tables:
Date Table
Date | Month | Year |
2024-01-01 | January | 2024 |
2024-02-01 | February | 2024 |
2024-03-01 | March | 2024 |
2023-01-01 | January | 2023 |
2023-02-01 | February | 2023 |
2023-03-01 | March | 2023 |
Sales Table
Date | Sale | Region |
2024-01-01 | 1000.00 | North |
2024-02-01 | 1500.00 | South |
2024-03-01 | 2000.00 | North |
2023-01-01 | 1200.00 | South |
2023-02-01 | 1300.00 | North |
2023-03-01 | 1400.00 | South |
DAX Calculation To create a calculated table that includes a row for each combination of Year and Region, and a column with the total sales for each combination, you can use the following DAX expression:
YearlySalesByRegion = SUMMARIZE( Sales, 'Date'[Year], Sales[Region], "Total Sales", SUM(Sales[Sale]) )
How It Works
• Grouping by Year and Region: The SUMMARIZE function groups the data by the Year column from the Date table and the Region column from the Sales table.
• Calculating Total Sales: For each group, it calculates the total sales using the SUM function on the Sale column from the Sales table.
• Creating the Summary Table: The result is a new table with a row for each combination of Year and Region, and a column named "Total Sales" that contains the sum of sales for each combination.
Resulting Table
Year | Region | Total Sales |
2024 | North | 3000.00 |
2024 | South | 1500.00 |
2023 | North | 1300.00 |
2023 | South | 2600.00 |
This calculated table dynamically generates rows for each combination of Year and Region present in your data and calculates the total sales for each combination.
Conclusion
In this discussion, we explore how to use the SUMMARIZE function to group sales data by both year and region, demonstrating its capability to generate comprehensive summary tables that facilitate deeper data analysis. By understanding and applying this function, users can enhance their data modeling and reporting in Power BI.