SUMMARIZECOLUMNS in DAX: Group Data and Calculate Aggregated Values
In this article, we will learn how to use SUMMARIZECOLUMNS in DAX
to group data by a column, calculate aggregated values such as Total Sales,
and apply filters to control the result.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist
What Is SUMMARIZECOLUMNS in DAX?
SUMMARIZECOLUMNS is a DAX table function used to create a summarized
table by grouping data using one or more columns and calculating expressions such as
SUM, AVERAGE, COUNT, and other measures or expressions.
It is especially useful when writing DAX queries where you want to see an aggregated
result for each category, customer, region, product, or another grouping column.
SUMMARIZECOLUMNS creates a summarized table based on the grouping columns,
optional filters, and calculated expressions you provide.
1. Grouping Product Category and Calculating Total Sales
Query
EVALUATE
SUMMARIZECOLUMNS(
'Product'[Category],
"Total Sales", SUM(Sales[Sales Amount])
)
Step-by-step explanation
Step 1: EVALUATE
EVALUATE tells DAX to return the result of the table expression.
Since SUMMARIZECOLUMNS returns a table, it can be used directly after EVALUATE.
Step 2: SUMMARIZECOLUMNS
SUMMARIZECOLUMNS creates the summarized result table.
In this query, we are grouping the sales data by product category.
Step 3: ‘Product'[Category]
This is the grouping column. DAX creates one result row for each
category represented in the summarized result.
Step 4: “Total Sales”
This is the name assigned to the calculated output column.
Step 5: SUM(Sales[Sales Amount])
The SUM function adds the values from
Sales[Sales Amount] for each category.
What will you get?
The query returns a summarized table containing the product category and the
corresponding total sales.
| Category | Total Sales |
|---|---|
| Category A | Calculated Sales |
| Category B | Calculated Sales |
| Category C | Calculated Sales |
The category names and sales values above are illustrative. Your actual result
will depend on the data available in your model.
The first argument after the table expression defines how the result is grouped,
while the name-expression pair creates the calculated output column.
2. Applying a Filter with SUMMARIZECOLUMNS
Query
EVALUATE
SUMMARIZECOLUMNS(
'Product'[Category],
FILTER('Product', 'Product'[Color] = "Red"),
"Total Sales", SUM(Sales[Sales Amount])
)
Step-by-step explanation
Step 1: EVALUATE
EVALUATE returns the table generated by
SUMMARIZECOLUMNS.
Step 2: ‘Product'[Category]
The result is grouped by Product[Category], so the output is organized
category by category.
Step 3: FILTER(‘Product’, ‘Product'[Color] = “Red”)
The FILTER expression filters the Product table so that
only products whose Color is “Red” are included in the
calculation context.
Step 4: “Total Sales”
This defines the name of the calculated output column.
Step 5: SUM(Sales[Sales Amount])
DAX calculates the sum of Sales[Sales Amount] for the summarized
category results while the Red product filter is applied.
What will you get?
The result is a category-level sales summary based on the products that satisfy
the filter condition Product[Color] = “Red”.
| Category | Total Sales |
|---|---|
| Category A | Red Product Sales |
| Category B | Red Product Sales |
| Category C | Red Product Sales |
The values above are illustrative. The actual result depends on the relationships
and data in your model.
You can add a filter expression to SUMMARIZECOLUMNS to restrict
the data considered by the summarized calculation.
Understanding the Structure of SUMMARIZECOLUMNS
The two queries demonstrate the main building blocks of
SUMMARIZECOLUMNS:
SUMMARIZECOLUMNS(
Grouping Column,
Filter Expression,
"Calculated Column", Expression
)
The filter expression is optional. Therefore, the first query uses the grouping column
followed directly by the calculated expression, while the second query adds a filter
between them.
| Component | Purpose |
|---|---|
| ‘Product'[Category] | Groups the result by product category |
| FILTER(‘Product’, ‘Product'[Color] = “Red”) | Restricts the calculation to Red products |
| “Total Sales” | Names the calculated output column |
| SUM(Sales[Sales Amount]) | Calculates the total sales value |
Comparing the Two Queries
| Query | Grouping | Filter | Calculation |
|---|---|---|---|
| Query 1 | Product Category | No additional filter | Total Sales |
| Query 2 | Product Category | Color = Red | Total Sales |
Important Notes
1. SUMMARIZECOLUMNS returns a table
SUMMARIZECOLUMNS produces a table containing the grouping columns
and the calculated expressions specified in the query.
2. Grouping determines the level of the result
In these examples, ‘Product'[Category] determines that the result
should be summarized at the product-category level.
3. Filters can be added to the query
The second query demonstrates how a FILTER expression can be included
to restrict the data before calculating Total Sales.
4. Calculated columns can be given custom names
The expression “Total Sales”, SUM(Sales[Sales Amount]) creates
an output column named Total Sales.
📝 Practice Exercise
Try modifying the query to summarize Total Sales by another
grouping column available in your model.
Then add a FILTER expression and change the product color condition
to another color available in your Product table.
Conclusion
In this article, we learned how to use SUMMARIZECOLUMNS to create
summarized DAX query results.
- SUMMARIZECOLUMNS creates a summarized table.
- ‘Product'[Category] groups the result by product category.
- “Total Sales”, SUM(Sales[Sales Amount]) calculates total sales for each summarized result.
- A FILTER expression can be added to restrict the data used in the calculation.
- The second query summarizes sales specifically for products where Color = “Red”.
SUMMARIZECOLUMNS is an important DAX query function for creating
grouped analytical results and applying filter conditions to those results.
📥 Practice Data:
Download Practice Data Free
🎥 Prefer learning through video?
DAX YouTube Playlist