ADDCOLUMNS
A table with new columns, each an expression evaluated for its rows.
Group: Table manipulation. Compatible with DAX.
Syntax
ADDCOLUMNS ( <table>, <name>, <expression> [, <name>, <expression>] … )
| Parameter | Type | Description |
|---|---|---|
table | Table | The rows to extend: a table of the model or any table expression. |
name | Text repeatable | The name of a new column, in quotes. It must not be a name the table already has. |
expression | Expression repeatable, evaluated for each row | The value worked out for each row, for the column named just before it. |
Returns
Table. Every row and column of the table, followed by the new columns.
Remarks
- Each expression runs once per row, with that row as its row context. A measure in it sees the row as a filter (context transition); a plain aggregation such as
SUM ( Sales[Liters] )does not, and shows the same total on every row unless you wrap it inCALCULATE. - The rows stay as they come: none is added, removed or merged, and duplicates remain.
- A new name must differ from every column of the table, whatever the case of its letters; reusing one is an error.
- To keep only some columns, or to rename them, use
SELECTCOLUMNS; to group first, putSUMMARIZEorVALUESinside.
Examples
Revenue of each order line
The Cider line has no liters, so its revenue is blank.
EVALUATE
VAR Orders =
DATATABLE (
"Product", STRING, "Liters", INTEGER, "Price", DOUBLE,
{ { "Pils", 120, 38 }, { "IPA", 80, 64 }, { "Cider", BLANK (), 52 }, { "Stout", 45, 70 } }
)
RETURN
ADDCOLUMNS ( Orders, "Revenue", [Liters] * [Price] )
ORDER BY [Product]
| Product | Liters | Price | Revenue |
|---|---|---|---|
| Cider | (blank) | 52 | (blank) |
| IPA | 80 | 64 | 5120 |
| Pils | 120 | 38 | 4560 |
| Stout | 45 | 70 | 3150 |
A measure next to a plain SUM
The measure takes each product's row as a filter. SUM on its own does not, so it repeats the total of all products.
EVALUATE
ADDCOLUMNS (
VALUES ( Products[Product] ),
"Liters", [Liters sold],
"Without the measure", SUM ( Sales[Liters] )
)
ORDER BY Products[Product]
| Products[Product] | Liters | Without the measure |
|---|---|---|
| Cider | 301074 | 1806463 |
| IPA | 331884 | 1806463 |
| Lettøl | 169179 | 1806463 |
| Pils | 1004326 | 1806463 |
Related functions
SELECTCOLUMNS, SUMMARIZE, SUMMARIZECOLUMNS, CALCULATE, FILTER.