Using variables in DAX
Analysis Services DAX expressions also support using variables to simplify complex expressions by separating a single expression into a series of more easily understood expressions. As previously mentioned, variables also allow a given DAX expression to reuse logic within the same expression, which could improve query performance.
Variables can be defined anywhere in a DAX expression and for any data type, including tables, using the following syntax:
VARIABLENAME = RETURNEDVALUE
To create a variable definition, use the VAR
keyword, as seen in the following code sample:
= VAR SumQuantity = SUM('Internet Sales'[Order Quantity]) RETURN IF( SumQuantity > 1000, SumQuantity * 0.95, SumQuantity * 1.10 )
A DAX expression can have as many variables as the model author needs. Each variable will...