Using Advanced Editor to modify M code
You can use the advanced editor if you wish to see the code that Power Query Editor is creating with each step, or you want to create your own shaping code. Use the following steps to open the advanced editor –
- Firstly, select the View tab on the ribbon, and then select Advanced Editor.
- Then, a window appears, showing the existing query code.
- Then, you can directly edit the code in the Advanced Editor window.
- Lastly, to close the window, select the Done or Cancel button.
Whenever you shape data in Power Query, steps are created in the Power Query process. Moreover, these steps can be reordered, deleted, and modified where it makes sense. Each cleaning step that you made was likely created by using the graphical interface, but the Power Query uses the M language behind the scenes. Some of the features of M code are –
- Firstly, the combined steps are available to read by using the Power Query Advanced Editor.
- The M language is always available to be read and modified directly.
- It is not required that you use M code to take advantage of Power Query.
- You will rarely need to write M code, but it can still prove useful.
- Because each step in Power Query is written in M code, even if the UI created it for you, you can use those steps to learn M code and customize it to suit your needs.
- After creating steps to clean data, select the View ribbon of Power Query and then select Advanced Editor.
Remember, each Power Query step will roughly align with one or two lines of M code. Indeed, you are not required to be an expert in M code to be able to read it. Moreover, you can even experiment by changing it. For instance, if you need to change the name of a database, you can do it right in the code and then select Done.