Debug DAX variables in Power BI and Power Pivot

When you’re dealing with a beast like DAX you can use any help there is, right? So here I show you how you can debug DAX variables who contain tables or show the result of multiple variables at once. So you can easily compare them with each other to spot the reason for problems fast.

Please note, that currently only comma separated DAX code is supported.

Example

Watch this measure from Gerhard Brueckl’s brilliant solution for dynamic TopN clustering with others. It contains 5 variables who return tables and one variable with a scalar:

Measure with variables who contain tables and scalars

If you want to follow along how this calculation is evolving for each value in a matrix, my VarDebugMeasure will show details of every variable like so:

Measure to debug DAX variables

Method

This method is a variation of my previous blogpost, which made the elements of tables in a CALCULATE function visible. Cool thing with the new function for variables is, that you can see details of all your variables in one measure (see picture above).

Code to debug DAX variables

Code parameters

Because one cannot paste text with linebreaks into the function dialogue in the query editor, I opted for a separate query that holds the code from the measure with the variables to investigate. If you name it “DAXVariableMeasureCode” like the default in the function, all have to do is to fill in the first parameter of the function like so:

  1. A comma separated text string that lists one value for each variable: If the variable represents a table, then the column name whose values shall be shown. For scalars, the null-value has to be entered.
  2. Optional: Number for how many sample values shall be shown. Default value is 10. So if you want to change it, just put in a different number in here.
  3. Full code of the measure that includes the variable (including the measure name)

6 steps to wow

  1. Copy the function code:
  2. Create a new query in the query editor and replace the existing code with the copied code (Strg+A, Strg+V)
  3. Create another new query (named “DAXVariableMeasureCode”) where you paste the DAX-code of the measure that contains the variables.
  4. Call the function with the parameters described under “Code parameters”. In my example, this looks like so:

    Call function

  5. Copy the resulting DAX code

    Copy DAX function code

  6. Create new measure where you paste the copied DAX code
  7. Drag that measure into a table or matrix beside the original measures

Please follow along these steps in this video:

You can download the file with examples here:  Debug DAX Variables

Enjoy & stay queryious ūüėČ

Comment (1) Write a comment

  1. Pingback: Text.RemoveBetweenDelimiters function for Power BI and Power Query – The BIccountant

Leave a Reply

Die Datenschutzbestimmungen finden Sie hier: / Please find the privacy policy here: https://wp.me/P6lgsG-Rz