SELECTCOLUMNS

The SELECTCOLUMNS function returns a table made up of columns calculated from an existing table or from an expression that returns a table.

Syntax

SELECTCOLUMNS(
    table,
    name,
    scalar_expression
    [,name, scalar_expression]
)

Parameters
  • table: Reference to an existing table or expression that returns a table.
  • name: Name to give to the calculated column.
  • scalar_expression: DAX expression that returns a scalar expression as a column reference, an integer, or a text string.
Returned value

The SELECTCOLUMNS function returns a table.

Additional Information

The SELECTCOLUMNS function behaves similarly to that of the ADDCOLUMNS function except for the fact that, instead of adding the columns to the table included as the first argument, they are added to an empty table.

The name of the calculated columns must be enclosed in double quotes.

The result of this function removes duplicate rows. See example below.

Examples

If we have a Geography table containing information about geographic locations, we can create a table from it that includes the postal code, the country and the sales in each location with the following measure:

Sales per territory =
SELECTCOLUMNS(
    Geography,
    "Postal code", Geography[PostalCode],
    "Country", Geography[Country],
    "Sales", [Total sales]
)

SELECTCOLUMNS function. Example of use

The result of the function removes duplicate rows. This can be easily verified if we start from the following scenario:

  • Vendors table:
Vendors table
  • Sales table:
Sales table

Note that each vendor has made two sales and that vendor 1's sales have been of the same product (product 1). The two sales of the other two sellers have been of different products.

Now let's create a calculated table with the SELECTCOLUMNS function in which, starting from the sales table, we show the identifiers of the sellers:

Sales listing = 
    SELECTCOLUMNS(
        Ventas,
        "Vendedor", Ventas[Id Vendedor]
    )

SELECTCOLUMNS function

We see that it only shows one row per seller. Now let's add a second column with the identifiers of the products sold:

Sales listing = 
    SELECTCOLUMNS(
        Ventas,
        "Vendedor", Ventas[Id Vendedor],
        "Producto", Ventas[Id Producto]
    )

SELECTCOLUMNS function

Again we see that the combination (Seller = 1, Product = 1) only appears once, when there are two records with this content.

Related functions
Category
Statistical
Submitted by admin on Tue, 01/22/2019 - 22:08