OpenBI Docs Buy

SELECTCOLUMNS

A table's rows with the columns named, each a column or an expression.

Group: Table manipulation. Compatible with DAX.

Syntax

SELECTCOLUMNS ( <Table>, [<Name>,] <Expression> [, [<Name>,] <Expression>] … )
ParameterTypeDescription
TableTableThe rows to go through: a table of the model or any table expression.
NameText
optional, repeatable
The name of a column of the result. It may be left out before a plain column reference, which then keeps its own name.
ExpressionExpression
repeatable, evaluated for each row
The column's value, worked out for each row.

Returns

Table. One row for each row of the table, with only the columns given, in that order.

Remarks

  • The rows are not grouped, so duplicates remain. Wrap it in DISTINCT, or use SUMMARIZE or VALUES, to get each value once.
  • A plain column reference stays tied to its column of the model under its new name, so the result still filters that column in CALCULATE. Any other expression, even Products[Product] & "", gives plain values.
  • Every name must be different; reusing one is an error, whatever the case of its letters.
  • Unlike ADDCOLUMNS, it leaves out every column of the table you do not name.

Examples

A renamed column and a computed one

EVALUATE
VAR Orders =
    DATATABLE (
        "Product", STRING, "Liters", INTEGER, "Price", DOUBLE,
        { { "Pils", 120, 38 }, { "IPA", 80, 64 }, { "Cider", BLANK (), 52 }, { "Stout", 45, 70 } }
    )
RETURN
    SELECTCOLUMNS ( Orders, "Beer", [Product], "Revenue", [Liters] * [Price] )
ORDER BY [Beer]
BeerRevenue
Cider(blank)
IPA5120
Pils4560
Stout3150

A column keeps its tie to the model

Both tables hold the three beers' names. The first still filters Products[Product]; the second holds plain text and filters nothing, so the total of all products comes back.

EVALUATE
VAR Beer = FILTER ( Products, Products[Category] = "Beer" )
RETURN
    ROW (
        "By the column", CALCULATE ( [Liters sold], SELECTCOLUMNS ( Beer, "Name", Products[Product] ) ),
        "By an expression", CALCULATE ( [Liters sold], SELECTCOLUMNS ( Beer, "Name", Products[Product] & "" ) )
    )
By the columnBy an expression
15053891806463

A name left out

Places[Place] keeps its own name.

EVALUATE
SELECTCOLUMNS (
    TOPN ( 3, Places, Places[Crates], DESC, Places[Place], ASC ),
    Places[Place],
    "Crates", Places[Crates]
)
ORDER BY [Crates] DESC, Places[Place]
Places[Place]Crates
Shop Grünerløkka18
Shop Bjørvika16
Shop St. Hanshaugen15

ADDCOLUMNS, SUMMARIZE, DISTINCT, VALUES, ROW.

Last updated · OpenBI Studio 0.3.74