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>] … )
| Parameter | Type | Description |
|---|---|---|
Table | Table | The rows to go through: a table of the model or any table expression. |
Name | Text 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. |
Expression | Expression 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 useSUMMARIZEorVALUES, 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, evenProducts[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]
| Beer | Revenue |
|---|---|
| Cider | (blank) |
| IPA | 5120 |
| Pils | 4560 |
| Stout | 3150 |
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 column | By an expression |
|---|---|
| 1505389 | 1806463 |
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økka | 18 |
| Shop Bjørvika | 16 |
| Shop St. Hanshaugen | 15 |
Related functions
ADDCOLUMNS, SUMMARIZE, DISTINCT, VALUES, ROW.