SELECTCOLUMNS DAX Function in Power BI

The SELECTCOLUMNS DAX function returns a table with selected columns from the table and new columns specified by the DAX expressions.

DAX Syntax

SELECTCOLUMNS(
    Table,
    Name1, Expression1,
    Name2, Expression2,
    ...
)         

The function has the following parameters:

The function returns 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.

Example: Let’s we have the following table named Students.

SELECTCOLUMNS dax function in Power BI

Let’s create a new table by clicking on “New table”.

SELECTCOLUMNS dax function in Power BI

And specify the following dax expression to it.

DAX

Table 5 = SELECTCOLUMNS('Students', "ID", [EmployeeID], "Combined", [Name] & " " & [Marks] )

The above DAX expression returns a new table as shown in the image below:

SELECTCOLUMNS dax function in Power BI

Note: Here & is the concatenation operator.

We can also specify the virtual table in the first argument and then perform the calculation on the virtual table.

DAX

Table 5 = SELECTCOLUMNS(FILTER('Students', VALUE([Marks]) >30), "ID", [EmployeeID], "Combined", [Name] & " " & [Marks] )

The above DAX expression returns a new table as shown in the image below:

SELECTCOLUMNS dax function in Power BI

Here, • FILTER('Students', VALUE([Marks]) >30) The DAX expression creates a virtual table by filtering the 'Students' table to include only rows where the numeric value of the Marks column is greater than 30. The VALUE function is used to convert the Text to Numeric datatype. • "ID", [EmployeeID], "Combined", [Name] & " " & [Marks] The SELECTCOLUMNS function define the structure of the new table, including two columns: "ID", which extracts and renames the EmployeeID column, and "Combined", which concatenates the Name and Marks columns into a single string separated by a space.