Step Descriptions And Comments In M Code In Power BI Desktop

The June release of Power BI Desktop has what seems to be a fairly unremarkable new feature in that it allows you to add descriptions to each step in a query in the Query Editor window. However the implementation turns out to be a lot more interesting than you might expect: the step descriptions become comments in the M code, and even better if you write M code in the Advanced Editor window your comments appear as descriptions in the Applied Steps pane.

Take the following M query, entered in the Advanced Editor, as an example:

let
    Step1 = 5,
    Step2 = 10,
    Step3 = Step1 * Step2
in
    Step3

There are three variables declared in the let expression which appear as three steps in the Applied Steps pane. The first two steps declare integers and the third multiplies these two integers together, returning 50.

If you right-click on the first step and select Properties, then you can enter a description for the step in the Properties pane that appears:

image

image

After you click OK, the description is visible as a tooltip when you mouse-over the step:

image

If you then open the Advanced Editor window you’ll see the M code for the query has now been changed to include a comment (NB comments in M code start with //):

let
    // Declare the first number
    Step1 = 5,
    Step2 = 10,
    Step3 = Step1 * Step2
in
    Step3

image

If you then edit the M code in the Advanced Editor window to add a comment in the line before a step, like so:

let
    // Declare the first number
    Step1 = 5,
    Step2 = 10,
    // Multiple the two numbers together
    Step3 = Step1 * Step2
in
    Step3

…then this will also show up as a description when you mouse-over the step in the Applied Steps pane:

image

As a result, for anyone like me who writes a lot of M code manually in the Advanced Editor window, this turns out to be a really handy feature.

8 thoughts on “Step Descriptions And Comments In M Code In Power BI Desktop

  1. This is great and pushes me even further towards using desktop in preference to Excel. We just need proper intellisense now and intuitive wizards so you’re not scratching around to find the function you need or translate the equivalent function in Excel. I don’t think either are too far away either.
    Got a two week holiday coming up so I’m going to immerse myself fully in this website and KP’s to catch up properly on all the valuable stuff you guys have been posting

  2. These continuous improvements are making an extremely useful and powerful tool even more user friendly. Great work !

  3. I’ll be the odd man out here and say that this is probably one of my least favorite features ever implemented. I favor coding practices that suggest minimizing comments in code, for good reasons. Comments are even less necessary in M than an imperative language.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s