SUMMARIZE in DAX: Group Data and Calculate Aggregations
In this article, we will learn how to use the SUMMARIZE function in DAX to group data by one or more columns and calculate aggregated values such as Total Sales and Total Tax.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist
What Is SUMMARIZE in DAX?
SUMMARIZE is a DAX table function used to create a summary table by grouping data based on one or more columns. It can also add calculated expressions, such as SUM, AVERAGE, COUNT, and other aggregations, to the grouped result.
The basic syntax is:
SUMMARIZE(
<Table>,
<GroupBy_Column>,
<GroupBy_Column>,
"Name", <Expression>
)
In our example, the Sales table is summarized using Product Category and Product Subcategory, while Total Sales and Total Tax are calculated for each group.
SUMMARIZE is useful when you need to group rows and return aggregated business metrics for each group.
1. Retrieve the Sales Table
Before creating the summary, the query first retrieves the complete Sales table.
EVALUATE
Sales
Step-by-step explanation
Step 1: EVALUATE
EVALUATE is used to return a table expression as the query result.
Step 2: Sales
Sales is the table expression being returned. Therefore, the complete Sales table is displayed.
This query is used to inspect the source Sales data before creating the grouped summary.
2. Retrieve the Product Table
The next query retrieves the complete Product table.
EVALUATE
'Product'
Step-by-step explanation
Step 1: EVALUATE
The EVALUATE statement returns the result of the table expression.
Step 2: ‘Product’
‘Product’ is the table being returned. The single quotes are commonly used when referencing a table name.
This query allows us to inspect the Product table, including the Category and Subcategory columns that will be used for grouping.
3. Create a Summary Using SUMMARIZE
Query
EVALUATE
SUMMARIZE(
Sales,
'Product'[Category],
'Product'[Subcategory],
"Total Sales", SUM(Sales[Sales Amount]),
"Total Tax", SUM(Sales[Tax Amount])
)
Step-by-step explanation
Step 1: EVALUATE
EVALUATE returns the summary table generated by the SUMMARIZE function.
Step 2: SUMMARIZE
SUMMARIZE creates a new table by grouping the data according to the columns specified after the source table.
Step 3: Sales
Sales is the table from which the summary is created.
Step 4: ‘Product'[Category]
This column is used as the first grouping column. The result will contain one group for each relevant product category.
Step 5: ‘Product'[Subcategory]
This column is used as the second grouping column. The result is therefore grouped by the combination of Category and Subcategory.
Step 6: “Total Sales”
This is the name of the calculated output column.
Step 7: SUM(Sales[Sales Amount])
The SUM function calculates the total Sales Amount for each Category and Subcategory group.
Step 8: “Total Tax”
This is the name of another calculated output column.
Step 9: SUM(Sales[Tax Amount])
The SUM function calculates the total Tax Amount for each Category and Subcategory group.
What will you get?
The result is a summary table containing the grouping columns and the calculated totals.
| Category | Subcategory | Total Sales | Total Tax |
|---|---|---|---|
| Components | Brakes | Aggregated Sales Amount | Aggregated Tax Amount |
| Components | Chains | Aggregated Sales Amount | Aggregated Tax Amount |
| Clothing | Jerseys | Aggregated Sales Amount | Aggregated Tax Amount |
The values above are illustrative. Your actual results depend on the data available in the Sales and Product tables.
Understanding the Structure of SUMMARIZE
The SUMMARIZE function can be understood as two main parts:
- Grouping columns define how the rows should be grouped.
- Calculated expressions define the metrics that should be returned for each group.
SUMMARIZE(
Sales,
'Product'[Category],
'Product'[Subcategory],
"Total Sales", SUM(Sales[Sales Amount]),
"Total Tax", SUM(Sales[Tax Amount])
)
| Part | Purpose |
|---|---|
| Sales | Source table |
| ‘Product'[Category] | First grouping column |
| ‘Product'[Subcategory] | Second grouping column |
| “Total Sales” | Name of the calculated output column |
| SUM(Sales[Sales Amount]) | Calculates Total Sales for each group |
| “Total Tax” | Name of the calculated output column |
| SUM(Sales[Tax Amount]) | Calculates Total Tax for each group |
Category and Subcategory Grouping
When both Category and Subcategory are specified, DAX groups the data using their combination.
For example, a result conceptually looks like this:
| Category | Subcategory |
|---|---|
| Components | Brakes |
| Components | Chains |
| Clothing | Jerseys |
Each unique combination of Category and Subcategory becomes a group, and the aggregation expressions are evaluated for that group.
Adding more grouping columns creates a more detailed summary because DAX groups the data based on the combination of those columns.
Understanding the Calculated Columns
The expressions after the grouping columns create additional columns in the summary table.
"Total Sales", SUM(Sales[Sales Amount]),
"Total Tax", SUM(Sales[Tax Amount])
“Total Sales” is the name assigned to the first calculated column, while SUM(Sales[Sales Amount]) calculates its value.
Similarly, “Total Tax” is the name assigned to the second calculated column, while SUM(Sales[Tax Amount]) calculates its value.
In SUMMARIZE, the pattern “Column Name”, Expression allows you to add calculated columns to the summary result.
Important Notes
1. SUMMARIZE returns a table
SUMMARIZE is a table function. Therefore, it can be used directly with EVALUATE in a DAX query.
2. Multiple grouping columns are supported
You can provide multiple columns to create a more detailed grouping, as demonstrated with Category and Subcategory.
3. Aggregations can be added to the summary
Functions such as SUM can be used to calculate metrics for each group. The expressions are evaluated against the corresponding grouped context.
4. The original tables are not modified
SUMMARIZE creates a table expression for the query result. It does not modify the original Sales or Product table.
📝 Practice Exercise
Try modifying the query to create a summary by Product Category and Subcategory and calculate another business metric from the Sales table.
For example, try adding Average Sales Amount.
Expected Pattern
EVALUATE
SUMMARIZE(
Sales,
'Product'[Category],
'Product'[Subcategory],
"Total Sales", SUM(Sales[Sales Amount]),
"Total Tax", SUM(Sales[Tax Amount]),
"Average Sales", AVERAGE(Sales[Sales Amount])
)
Conclusion
In this article, we learned how to use SUMMARIZE to create grouped summary tables in DAX.
- SUMMARIZE creates a summary table from a source table.
- Grouping columns determine how the data is summarized.
- Multiple grouping columns can be used together, such as Category and Subcategory.
- Calculated expressions can be added using the “Name”, Expression pattern.
- SUM can be used to calculate Total Sales and Total Tax for each group.
- The original Sales and Product tables remain unchanged.
SUMMARIZE is an important table function for building grouped analytical results and is especially useful when working with DAX queries in tools such as DAX Studio.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist