SUMMARIZE
A table's groups by columns of it or of related tables, optionally with columns computed for each group.
Group: Table manipulation. Compatible with DAX.
Syntax
SUMMARIZE ( <table>, <groupBy_columnName> [, <groupBy_columnName>] … [, <name>, <expression>] … )
| Parameter | Type | Description |
|---|---|---|
table | Table | The table whose rows are grouped, often a fact table such as Sales. |
groupBy_columnName | Column repeatable | A column to group by: the table's own, or a column of a table it reaches through relationships, such as Products[Category] from Sales. |
name | Text optional, repeatable | The name of an added column, in quotes. |
expression | Expression optional, repeatable | Its value for each group, with the group as filter. |
Returns
Table. One row for each combination of the grouping columns' values that occurs in the table's rows, with any added columns.
Remarks
- Only combinations that occur come out: grouping Sales by category and kind of place gives no depot rows, as depots sell nothing.
CROSSJOINwould list them. - Columns of related tables are reached along the relationships, from the many side to the one side. A column the table cannot reach is an error.
- For added columns, prefer
ADDCOLUMNSaround SUMMARIZE, as in the second example: name and expression pairs inside SUMMARIZE work, but in a context that is harder to predict. - With
ROLLUPamong the grouping columns it adds subtotal rows, whichISSUBTOTALtells apart.
Examples
The combinations that occur
EVALUATE
SUMMARIZE ( Sales, Products[Category], Places[Kind] )
ORDER BY Products[Category], Places[Kind]
| Products[Category] | Places[Kind] |
|---|---|
| Beer | Shop |
| Cider | Shop |
Groups with computed columns
EVALUATE
ADDCOLUMNS (
SUMMARIZE ( Sales, Products[Category] ),
"Liters", [Liters sold],
"Shops", CALCULATE ( DISTINCTCOUNT ( Sales[Shop] ) )
)
ORDER BY Products[Category]
| Products[Category] | Liters | Shops |
|---|---|---|
| Beer | 1505389 | 15 |
| Cider | 301074 | 15 |
A table made in the query
EVALUATE
VAR Sold =
DATATABLE (
"Shop", STRING, "Product", STRING, "Liters", INTEGER,
{ { "A", "Pils", 10 }, { "A", "IPA", 5 }, { "B", "Pils", 7 }, { "B", "Pils", 3 } }
)
RETURN
SUMMARIZE ( Sold, [Shop] )
ORDER BY [Shop]
| Shop |
|---|
| A |
| B |