OpenBI Docs Buy

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>] … )
ParameterTypeDescription
tableTableThe rows to extend: a table of the model or any table expression.
nameText
repeatable
The name of a new column, in quotes. It must not be a name the table already has.
expressionExpression
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 in CALCULATE.
  • 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, put SUMMARIZE or VALUES inside.

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]
ProductLitersPriceRevenue
Cider(blank)52(blank)
IPA80645120
Pils120384560
Stout45703150

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]LitersWithout the measure
Cider3010741806463
IPA3318841806463
Lettøl1691791806463
Pils10043261806463

SELECTCOLUMNS, SUMMARIZE, SUMMARIZECOLUMNS, CALCULATE, FILTER.

Last updated · OpenBI Studio 0.3.74