SELECTCOLUMNS DAX Function (Table manipulation)

Returns a table with selected columns from the table and new columns specified by the DAX expressions.

Syntax

SELECTCOLUMNS ( <Table>, <Name>, <Expression> [, <Name>, <Expression> [, … ] ] )
Parameter Attributes Description
Table
Iterator

The table from which columns are selected.

Name Repeatable

The name of the new column to be added.

Expression
Row Context
Repeatable

The expression for the new column to be added.

Return values

Table An entire table or a table with one or more columns.

A table with the same number of rows as the table specified as the first argument. The returned table has one column for each pair of Name, Expression arguments, and each expression is evaluated in the context of a row from the specified Table argument.

Remarks

SELECTCOLUMNS has the same signature as ADDCOLUMNS, and has the same behavior except that instead of starting with the <Table> specified, SELECTCOLUMNS starts with an empty table before adding columns.
SELECTCOLUMNS keep the data lineage of the columns assigned to a simple column reference. Any different expression breaks the data lineage.

» 3 related articles
» 1 related function

Examples

--  SELECTCOLUMNS is an iterator that returns a selection of
--  columns / expressions evaluated in the row context during
--  the iteration over its first parameter.
EVALUATE
    SELECTCOLUMNS ( 
        TOPN ( 10, 'Product' ),
        "Product Category", 'Product'[Category],
        "Product Subcategory", 'Product'[Subcategory],
        "Product Color", 'Product'[Color],
        "Product Name", 'Product'[Product Name],
        "#Products", CALCULATE ( COUNTROWS ( 'Product' ) ),
        "Sales", [Sales Amount]
    )
Product Category Product Subcategory Product Color Product Name #Products Sales
Computers Computers Accessories Black Contoso Rechargeable Battery E100 Black 1 602.30
Computers Computers Accessories Black Contoso Dual USB Power Adapter – power adapter E300 Black 1 2,655.35
Computers Computers Accessories Black Contoso Car power adapter M90 Black 1 984.53
Computers Computers Accessories Black Contoso Notebook Peripheral Kit M69 Black 1 1,066.73
Computers Computers Accessories Black Contoso Mouse Lock Bundle E200 Black 1 554.26
Computers Computers Accessories Black Contoso Education Supplies Bundle E200 Black 1 1,157.62
Computers Computers Accessories Black Contoso Laptop Starter Bundle M200 Black 1 419.10
Computers Computers Accessories Black Contoso Education Essentials Bundle M300 Black 1 144.40
Computers Computers Accessories Black Contoso Desktop Alternative Bundle E200 Black 1 181.70
Computers Computers Accessories Black Contoso Power Inverter – DC to AC power inverter E900 Black 1 365.09
--  SELECTCOLUMNS has a row context that can be used to write 
--  expressions that navigate through relationships.
EVALUATE
CALCULATETABLE (
    SELECTCOLUMNS (
        Sales,
        "Order Number", Sales[Order Number],
        "Order Line Number", Sales[Order Line Number],
        "Customer", RELATED ( Customer[Name] ),
        "Product", RELATED ( 'Product'[Product Name] ),
        "Quantity", Sales[Quantity],
        "Line Amount", Sales[Quantity] * Sales[Net Price]
    ),
    'Date'[Date] = DATE ( 2007, 9, 19 ),
    Customer[Customer Type] = "Person"
)
Order Number Order Line Number Customer Product Quantity Line Amount
20070919123936 1 Vazquez, Monique Contoso 512MB MP3 Player E51 Blue 4 46.76
20070919525615 1 Hall, Destiny The Phone Company Touch Screen Phones – CRT M11 Grey 4 680.40
20070919123935 1 Barnes, Alexis Contoso 512MB MP3 Player E51 Blue 1 11.69
20070919123937 1 Ruiz, Eddie Contoso 512MB MP3 Player E51 Blue 1 11.69
20070919123941 1 Anderson, Eduardo Contoso 512MB MP3 Player E51 Blue 1 11.69
20070919427828 1 Gao, Ernest Fabrikam Social Videographer 2/3” 17mm E100 Grey 1 144.00
20070919712464 1 Cook, Jared MGS Rise of Nations2009 E152 1 38.70
20070919712465 1 Patel, Cassandra MGS Rise of Nations2009 E152 1 38.70
20070919712466 1 He, Willie MGS Rise of Nations2009 E152 1 38.70
20070919712467 1 Jones, Jennifer MGS Rise of Nations2009 E152 1 38.70
20070919525616 1 Rubio, Jésus The Phone Company Touch Screen Phones – CRT M11 Grey 1 170.10
20070919525617 1 Shan, Leonard The Phone Company Touch Screen Phones – CRT M11 Grey 1 170.10
20070919525618 1 Hernandez, Albert The Phone Company Touch Screen Phones – CRT M11 Grey 1 170.10

Related articles

Learn more about SELECTCOLUMNS in the following articles:

Related functions

Other related functions are:

Last update: May 12, 2021   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://docs.microsoft.com/en-us/dax/selectcolumns-function-dax

2018-2021 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of SELECTCOLUMNS? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.