Variables in DAX - Excelerator BI

Variables in DAX

Earlier this week I did a live stream event.  I put out a poll and asked people to tell me what topic they wanted me to talk about.  The options were

  1. Calculated Columns vs Measures
  2. Tips for Excel users moving to Power BI
  3. Using Variables in your DAX

The overwhelming response was 3. Using Variables in DAX.  In the video I covered the concept of variables and how they can be used to make your DAX easier to write, read, understand, and to debug.  In case you missed the live stream, I have it available on my YouTube Channel.  You can watch it below.

The promotion I talk about in the video is 20% off all training courses at http://skillwave.training.  The promotion ends on 12th Sept 2021.

4 thoughts on “Variables in DAX”

  1. Phenomenally done sir. It took some time, but getting into this habit has been a huge value add to my DAX! Shared this out with my team as well.

  2. Another clear training video, thanks Matt.
    Question on naming variables; I’ve seen variables starting with underscore “_” as a way if distinguishing them in DAX code. Is this a good/common practice?

    1. It is a practice, but I don’t think it’s common, and whether you think it’s “good” depends on your perspective. I’m not trying to say it’s bad, btw. When a query is auto generated by a visual (visible from the query performance panel), the query variables have a leading double __. My guess is that this is where the trend came from. Developers tend to do things like this probably originating from very early programming languages. Eg they may write a variable strName or intResult. The likely reason they use it here is to remove clashes with key words and identify the variables.

      But I teach business people DAX, and in the same way that I don’t encourage dimProduct or factSales for table names, I don’t see the benefit of this underscore apart from the key word clash avoidance.

      Just my view, of course.

  3. Very good tutorial on the use of variables in DAX.

    As Matt expertly states, variables are immutable in DAX. For Programmers/Developers from other disciplines the variable type means it can be varied, so this can cause initial confusion until understood.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top