DAX Other - VAR function


Advertisements


Description

Stores the result of an expression as a named variable, which can then be passed as a parameter to other calculated field expressions. Once the resultant values have been calculated for a variable expression, those values do not change, even if the variable is referenced in another expression.

DAX VAR function is new in Excel 2016.

Syntax

VAR <name> = <expression> 

Parameters

Sr.No. Term & Description
1

name

The name of the variable (identifier).

  • Delimiters are not supported. For e.g. ‘varName’ or [varName] will result in an error.

  • Supported character set: a-z, A-Z, 0-9.

    • 0-9 are not valid as first character.

    • __ (double underscore) is allowed as a prefix to the identifier name. No other special characters are supported.

  • Reserved keywords not allowed.

  • Names of the existing tables are not allowed.

  • Empty spaces are not allowed.

2

expression

A DAX expression which returns a scalar or table value.

Return Value

A named variable containing the result of the expression parameter.

Remarks

An expression passed as a parameter to VAR can contain another VAR declaration.

When referencing a variable −

  • Calculated fields cannot refer to variables defined outside the calculated field expression, but can refer to functional scope variables defined within the expression.

  • Variables can refer to calculated fields.

  • Variables can refer to previously defined variables.

  • Columns in table variables cannot be referenced via TableName[ColumnName] syntax.

Example

= Var SouthSales = SUMX(FILTER(Sales,Sales[Region]="South")
,Sales[Sales Amount]) Var EastSales = SUMX(FILTER(Sales,Sales[Region]="East")
,Sales[Sales Amount]) return SouthSales+EastSales 

dax_functions_other.htm

Advertisements