Power Query Editor Archive | THE SELF-SERVICE-BI BLOG Wir lieben Microsoft Power BI Fri, 22 Mar 2024 16:25:47 +0000 de hourly 1 https://wordpress.org/?v=6.7.2 https://ssbi-blog.de/wp-content/uploads/2019/10/Favicon-150x150.png Power Query Editor Archive | THE SELF-SERVICE-BI BLOG 32 32 Intellisense for Power Query/ M – finally https://ssbi-blog.de/blog/technical-topics-english/intellisense-for-power-query-m-finally/ https://ssbi-blog.de/blog/technical-topics-english/intellisense-for-power-query-m-finally/#comments Wed, 12 Sep 2018 00:27:33 +0000 https://ssbi-blog.de/?p=4292 With the current release of Power BI Desktop (September 2018), a feature is available that many Power Query fans have been waiting for for no less than 3 years: Intellisense in the editor. How much this feature was in demand I could clearly see in the past by the visits on my own website, because […]

Der Beitrag Intellisense for Power Query/ M – finally erschien zuerst auf THE SELF-SERVICE-BI BLOG.

]]>
With the current release of Power BI Desktop (September 2018), a feature is available that many Power Query fans have been waiting for for no less than 3 years: Intellisense in the editor. How much this feature was in demand I could clearly see in the past by the visits on my own website, because my article about creating an editor for M in Notepad++ was by far the most read one on my blog. So let’s take a look at this new preview feature together.

Activate the preview feature

At the time of writing Intellisense for Power Query in Power BI Desktop is in preview. To use this feature, you have to unlock it first in the options.

Activate the preview feature "M Intellisense", Power Query, Power BI Desktop
Activate the preview feature „M Intellisense“

Now that the feature is enabled, where can you take advantage of intellisense now?

„M Intellisense“ only available in the Advanced Editor

There are three different places in Power Query, where you can write M code:

  • The formular bar,
  • the add custom column window and
  • the advanced editor

At the time of writing, the „M intellisense“ feature is only available in the Advanced Editor, but not yet in the other two places. This will change in near future (see here), but for now, you have to use the advanced editor, to take advantage of M Intellisense. Let’s see what the M Intellisense feature delivers in the current version and what we have to wait for.

More than just Intellisense

While Microsoft names this feature M intellisense, it actually has more to offer. Let’s dig into this.

Intellisense

Intellisense is a term for code completion and it completes the M code as follows.

Calling members of #shared

Intellisense: Get a dropdown of all native M functions, Power Query, Power BI Desktop
Intellisense: Get a dropdown of all native M functions

Intellisense let’s you easily call members of the intrinsic variable #shared, which includes all the native M functions, custom functions, results of other queries and defined parameters within the Power Query instance. Type for exampleTable. and you get a list of all native Table functions, which you can select by using Tab on your keyboard, or the mouse. You can go the same way to reference results of other queries…

Intellisense: Reference other queries, Power Query, Power BI Desktop
Intellisense: Reference other queries

… custom functions…

Intellisense: Reference custom functions, Power Query, Power BI Desktop
Intellisense: Reference custom functions

and parameters:

Intellisense: Reference parameters, Power Query, Power BI Desktop
Intellisense: Reference parameters

  In all these cases you get a preview of the source code in red letters. But #shared doesn’t contain variables from the current Query. What’s with those elements?

Calling variables from inside the current M script

You can use intellisense to reference variables/ step names from inside the current query, even, if those variables contain spaces, which makes a prefixed sharp (#““) necessary. This will make our lives so much easier, while coding M!

Intellisense: Reference variables from the current query, Power Query, Power BI Desktop
Intellisense: Reference variables from the current query

Automatic closing of…

If you enter one of the following characters, the editor automatically creates a closing element for it:

  • Parentheses,
  • Quotes,
  • Square brackets,
  • Curly brackets

The prefixed icons

When using Intellisense, you will quickly notice that all elements of the drop-down list have one of two icons in front: The cube and the triangle, the circle and the square. The cube appears for all the native M functionstriangle, the circle and the square indicate all the other elements in the list, which are step names/ variables, parameters, other query names, constants, types, etc.

Two different icons, indicating the type of element to choose, Power Query, Power BI Desktop
Two different icons, indicating the type of element to choose

So much about Intellisense, but there are other features of the editor.

Keyword highlighting

Keyword highlighting highlights reserved keywords from the M language. In the current version of the feature minimum the following keywords are considered.  

Only special kleywords are highlighted yet, functions are still missing, Power Query, Power BI Desktop
Only some keywords are highlighted yet, functions are still missing

For some reason I do not know, none of the M functions are highlighted yet. I hope this will come soon.

Parameter hints and help texts

What would an editor be if it did not disclose the parameters for the respective functions and a help texts for its functionalities? We have all had to go through this painfully over the last few years: hundreds of functions with hundreds of parameters and no support from the editor. You can’t remember all those functions and parameters. This has now come to an end. From now on, we are supported by Parameter hints and help texts so that we don’t have to search through the documentation for hours, but can simply „tap on it“.

Parameter hints and help texts make the coders life a lot easier, Power Query, Power BI Desktop
Parameter hints and help texts make the coders life a lot easier

The box, in which the parameter hints and the help texts appear, sometimes contains a toggle button, as seen in the screenshot below. This toggle button ensures that optional parameters are shown (2/2) or hidden (1/2).

Toggle, to see optional parameters or hide them, Power Query, Power BI Desktop
Toggle, to see optional parameters or hide them

This functionality was not obvious to me and Imke first had to draw my attention to it. This is because even if you toggle to see the optional parameters of a function, those parameters are not prefixed by the word optional.

Comments and numbers

The longer the M scripts get, the more important becomes commenting. This feature is also included in the current version of the M editor:

Comment your code, to keep the overview, but don't get confused by the green numbers, Power Query, Power BI Desktop
Comment your code, to keep the overview, but don’t get confused by the equally coloured numbers

The only thing I do not like about this experience, is that numbers are highlighted in the same green as the comments, which IMHO makes it harder to read. I would love to see that changed in the future.

Simplified marking of code components

Marking code for copy and past operations was hard in M so far, especially, when your variable had spaces. Now it got pretty easy. Just double click the variable/ step name and it gets marked so you can easily copy and paste it.

Mark, copy and paste variable names in the M editor, Power Query, Power BI Desktop
Mark, copy and paste variable names in the M editor made easy

Display options

To be honest, while checking all the new features of the editor, I didn’t see the Display Options which should be quite obvious until relatively late. They are very useful for keeping track of the code. Display line numbers and Render Whitespace (the dotted lines) can be activated individually or in combination.

Commenting in the M editor, Power Query, Power BI Desktop
Using Display Options in the Advanced Editor

Indenting lines of Code

The structure in the code is almost as important as writing meaningful comments. Again, the current version of the editor supports this, if you press ENTER at the appropriate places in the M code. Pressing ENTER after a opening parenthesis:

 
Indenting lines, from within a function, Power Query, Power BI Desktop
Indenting lines, from within a function

Pressing ENTER after a equal sign:

Intending lines, after a equal sign, Power Query, Power BI Desktop
Intending lines, after a equal sign

So far to what is included in the current version of the editor. But what is missing. I wrote down what I think is still missing.

What’s still missing

Even if I am very satisfied after testing the editor so far, there are a few things I’m still missing:

  1. As I mentioned earlier, the highlighting of the native M functions is still missing. This should be done as soon as possible.
  2. We need intellisense not only in the advanced editor, but also in the formula bar and in the add custom column window (will come very soon, as stated here)
  3. Type declaration for parameter types and function types: When I define a parameter in e. g. VBA, then I get a dropdown for possible types. This does not yet happen, when I define types in custom functions in M, as the screenshot below shows (on the left VBA, on the right M).
Missing: Intellisense for type declaration, Power Query, Power BI Desktop
Missing: Intellisense for type declaration

4. We need all these great features in Power Query for Excel too 🙂

How do you like the new experience and what do you think about it? Did you find a feature I did not write about? Leave me a comment below 🙂 Regards from Germany, Lars I write my posts for you, the reader. Please take a minute to help me write my posts as well as possible. Thank you 🙂 [yasr_visitor_multiset setid=2]

Der Beitrag Intellisense for Power Query/ M – finally erschien zuerst auf THE SELF-SERVICE-BI BLOG.

]]>
https://ssbi-blog.de/blog/technical-topics-english/intellisense-for-power-query-m-finally/feed/ 4
Get your own Power Query Editor using Notepad++ https://ssbi-blog.de/blog/technical-topics-english/power-query-editor-using-notepad/ https://ssbi-blog.de/blog/technical-topics-english/power-query-editor-using-notepad/#comments Wed, 22 Feb 2017 18:26:26 +0000 http://ssbi-blog.de/?p=1214 Preface This post is not new. I published the first version on how to create your own Power Query Editor already in November 2015 on my old blog www.powerbi-usergroup.de. Many things changed since then. First: I changed my blog and created THE SELF-SERVICE-BI BLOG. Second: Many of the details I showed in my older post […]

Der Beitrag Get your own Power Query Editor using Notepad++ erschien zuerst auf THE SELF-SERVICE-BI BLOG.

]]>
Preface

This post is not new. I published the first version on how to create your own Power Query Editor already in November 2015 on my old blog www.powerbi-usergroup.de. Many things changed since then. First: I changed my blog and created THE SELF-SERVICE-BI BLOG. Second: Many of the details I showed in my older post to create your own editor for Power Query with Notepad++ didn’t work anymore. Several circumstances had changed, so I had to change the post as well. Now let’s go. Get your Power Query Editor 😉


Hello Power Query enthusiasts,

many of you know that Power Query is an amazing tool for data import and data transformation. It is powerful an easy to use. But there is always a BUT. It is a pain to write custom M code. The Power Query Advanced Editor comes without intellisense (auto completion), no parameter hints, no syntax highlighting, no help texts, which explain what the functions do, no nothing. The fact, that M is case sensitive doesn’t make it easier at all.

In 2015 I read the following article, written by Matt Masson. Matt is a Senior Program Manager at Microsoft and member of the Power BI Developer Team. He showed how to create an editor for Power Query with Notepad++. At that time I did not even know that it was possible to create a custom language in Notepad++. Thanks a lot Matt 🙂

Matt’s tool already had intellisense and syntax highlighting. What I was still missing was parameter hints and help texts. The number of Power Query functions are getting more every month and I am always looking for the right function for my specific problem. This is why I was investigating a bit and found a solution, which I hope will be helping others as well.

I use my editor mainly in two scenarios:

Scenario 1: Finding the right function for my problem

Finding the right function using the Power Query Editor
Finding the right function using the Power Query Editor

Using the editor makes it much easier to find the function that fits your needs. Especially the help texts help you to get more familiar with the M language.

Scenario 2: Taking a look at M code with highlighted keywords and comments

Working with highlighted syntax for Power Query M code
Working with highlighted syntax for Power Query M code

Syntax highlighting helps to keep (or get) an overview over your M code. Commenting becomes more important, the longer and complex your M code gets.

If you are dealing with these scenarios as well and you find my solution interesting, please read further and learn how to get it. It is completely FREE and will take your M Code to the next level 🙂

Let’s see how to get there.

What you need to do to get your Power Query Editor

Creating your own M editor in Notepad++ is not complicated and can be seperated in the following steps:

  1. Download Notepad++
  2. Creating Keywords highlighting via the GUI of Notepad++
  3. Adding parameter hints and help texts by using a specific XML file

I will guide to create your editor. Stay tuned 🙂

1. Download Notepad++

Of cause you need to download the free tool Notepad++ (e. g. from here).  I installed the first version („Take this one if you have no idea which one you should take„) on my machine.

2. Creating Keywords highlighting via the GUI of Notepad++

After you installed the software you need to do some modification in Notepad++. Go to Language and choose Define your language…

Define your own language
Define your own language

The form for defining the user defined language opens. Choose Create New… and give your language a name. I called it M.

Create a new language: M
Create a new language: M

Now you have to define special keywords and their styles. Go to tab Keywords Lists and fill the first group with all the functions from Power Query. (I provide this list for you at the very end of this article. Go there and click the link list of functions for keywords highlighting). Mark everything in Excel (ctrl + a), then copy (ctrl + c), move to 1st Group in Notepad++ and paste all the function into that box (ctrl + v). The result looks like this:

Add all functions as keyword
Add all functions as keyword

Then press Styler and style the keywords as you like it. I decide turn all my function keywords in deep blue and bold letter.

Style your keywords as you like it
Style your keywords as you like it

Take care also to select the check box for prefix mode. That way your keyword only get styled, when it is used as a prefix. And now comes one of the most important steps: Don’t ignore case 😉

M is case sensitive: Don't ignore case in Power Query
M is case sensitive: Don’t ignore case in Power Query

After we have defined all functions as keywords, we need to add some more keywords. The list of keywords is not complete. Feel free to add specific keywords and adjust the styles as you like it.

Define keywords for the Power Query language M
Define keywords for the Power Query language M

For your convenience copy the following words into the groups:

Group 2: let in

Group 3: each and as error true false is meta not or section shared type

Group 4: if then else

Group 5: try otherwise

Group 6: #binary #date #datetime #datetimezone #duration #infinity #nan #sections #shared #table #time ; Because the elements in the 6th group are used like function, take care to activate Prefix mode.

Now we’re coming to comments:

Adding tokens for commenting
Adding tokens for commenting

Use Styler in the same way as you did it before. I choose deep green as color for comments. To select Allow folding of comments does exactly what it says. It allows you to fold comments together, if you want to focus on the source code only.

The final step is to define the delimitors. Select the operators and deliminators tab.

Defining the delimiters
Defining the delimiters

For your convenience copy it from here:

Operators1:  „>, ; = & ( ) [ ] { } @ ! ? => .. … = < > <> + = * / <= >=</ #

Operators2:   and or not

There is no save button. So just click the cross in the upper right corner to close the dialog.

Adding styles by pushing the button Stylers is recommended… I suggest to use red color for Operators.

Now my code already has intellisense and highlights keywords. But I am still missing parameter hints and help texts.

3. Adding parameter hints and help texts by using a specific XML file

Adding parameter hints and help texts is easy for you. I already created the necessary XML file for you. At the very end of this article you find several links to download several files. I provide two files for auto completion and help texts: One in German and one in English. Download one of the following two files English auto completion file or German auto completion file from the very end of this article and put it into your APIs folder of Notepad++. On my machine I find it under …

C:\Program Files (x86)\Notepad++\plugins\APIs

Now restart your Notepad++, press ctrl+n for a new window and choose “M” as your language (as you can see in the following screenshot).

Selecting the M language in Notepad++
Selecting the M language in Notepad++

Now have fun writing M-statements much easier than before  😉

TAKE CARE: The name of the new language and the name of the XML file has to be the same. If you decide to use something different from M, keep this in mind. 

After each update of Power BI Desktop I will provide you with new files at the end of this article. Then just do 2 things:

  • Download the List of functions for Keywords highlightings. In Notepadd++ go to Language –> Define your language. Then go to tab Keywords Lists, delete all old Keywords from 1st group and put in the new Keywords from the List of functions for Keywords highlightings.

    Replacing old Keywords by new
    Replacing old Keywords by new
  • Download the XML file again and replace the old file (in folder …plugin\APIs\) by the new. That’s it.

See you next time and keep in mind: Sharing is caring. If you liked this article, feel free to share it

Greets from Hamburg,

Lars

Download files

8th of August 2018

This update contains 2 new functions:

  • Cdm.MapToEntity()
  • Python.Execute()

List of functions for Keywords highlighting

English auto completion file

German auto completion file

Attention: If these links prompt you to log in with your Microsoft account, please try Microsoft Edge. OneDrive is a bit bitchy at the moment, although I have released the link for everyone (without the need to log in).

Der Beitrag Get your own Power Query Editor using Notepad++ erschien zuerst auf THE SELF-SERVICE-BI BLOG.

]]>
https://ssbi-blog.de/blog/technical-topics-english/power-query-editor-using-notepad/feed/ 85