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...