Using variables when you define your measures will make your DAX code much easier to read. In some cases, it can also make your code perform more efficiently. We will look at the potential of improving code performance using variables in more detail when we look at optimizing DAX queries in Chapter 13, Optimizing Your DAX Queries.
The following code defines a measure that counts the number of products in a table, where the value of the ClassName column is equal to Deluxe:
Deluxe Products =VAR varDeluxeProducts = FILTER ( 'Product', 'Product'[ClassName] = "Deluxe" )RETURN COUNTROWS( varDeluxeProducts )
This example can be broken down as follows:
- The measure is defined using the ...