ADDCOLUMNS

The ADDCOLUMNS function adds calculated columns to a table or expression that returns a table.

Syntax

ADDCOLUMNS(
    <table>,
    <name>,
    <expression>
    [, <name>, <expresión>]
)

Parameters
  • table: Reference to an existing table or expression that returns a table.
  • name: Name to give to the calculated column.
  • expression: DAX expression that returns a scalar expression, evaluated for each row in the table.
Returned value

The ADDCOLUMNS function returns a table.

Additional Information

ADDCOLUMNS will evaluate the expressions that define the columns to be created in the row context defined by each of the rows of the table being iterated.

The table returned by the function will include all the original columns of the argument plus the calculated columns.

The ADDCOLUMNS function behaves similarly to the SELECTCOLUMNS 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.

Examples

Assuming that we start with a data model in which there is a Geography table with geographic information, another Sales table with sales information, and a [Sales] measure that sums the sales figures, we can create a calculated table with the list of countries extracted from the Geography[Country] field and a calculated column "Sales" with sales by country using the following DAX expression:

Country sales = 
ADDCOLUMNS(
    VALUES(Geography[Country]),
    "Sales", [Sales]
)
Función ADDCOLUMNS

Since the evaluation of the expression that will determine the values of the calculated column is performed in a row context, the reference to the [Sales] measure will force a context transition, so the result for each row will be the corresponding sales for the country indicated in the first column.

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