Using variables with measures, calculated columns, and tables

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:

  1. The measure is defined using the ...

Get Hands-On Business Intelligence with DAX now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.