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:

[sourcecode language='text'  padlinenumbers='true']
let
    Step1 = 5,
    Step2 = 10,
    Step3 = Step1 * Step2
in
    Step3
[/sourcecode]

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

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

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 //):

[sourcecode language='text'  highlight='2']
let
    // Declare the first number
    Step1 = 5,
    Step2 = 10,
    Step3 = Step1 * Step2
in
    Step3
[/sourcecode]

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

[sourcecode language='text'  highlight='5']
let
    // Declare the first number
    Step1 = 5,
    Step2 = 10,
    // Multiple the two numbers together
    Step3 = Step1 * Step2
in
    Step3
[/sourcecode]

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

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.

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

  1. Power Query once again has the GUI for users, and M code interface for programmers.

  2. 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

  3. wynhopkinsAA – Perth Western Australia – Director - Access Analytic - creating Amazing Excel and Power BI solutions enabling organisations to grow faster, reduce cost and control risk
    wynhopkins says:

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

  4. 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 ReplyCancel reply