Stop 05 · M Language & Advanced Power QueryTopics · 2/8

Advanced Editor

Part of the Power BI Roadmap

In short

The ribbon can only do what its buttons allow. The Advanced Editor shows the whole query as text, so you can fix a broken path, copy logic to another file or write a step no button offers.

The Advanced Editor shows the full M code of a query, so you can edit it directly, copy it between files or fix steps the interface can't.

The jaadu unscrews the back panel of a big washing machine and carefully adjusts the coloured wires inside with a small screwdriver.

Think of it like this

Opening the back panel of a machine

A washing machine has front buttons for normal use. A technician opens the back panel to see every wire and adjust what the buttons can't reach. The Applied Steps pane is the front buttons. The Advanced Editor is the back panel.

Watch it happen

Applied Steps vs Advanced Editor

Applied Steps

  • Click buttons to add steps
  • Gear icon edits one step
  • Great for learning and quick work
  • Can't express every idea

Advanced Editor

  • See and edit the whole query as M
  • Copy and paste between files
  • Write custom logic and functions
  • Fix many steps in one go

Build with buttons, then open the Advanced Editor to read, tidy and extend what they wrote.

The big ideas

What you need to know

Where to find it

Home > Advanced Editor or View > Advanced Editor in Power Query. It shows one query at a time.

Copy queries across files

Select all the text, paste it into a blank query in another .pbix, and the same steps rebuild there.

Syntax check

The editor flags problems at the bottom, like a missing comma, before you click Done.

Comments

Use // for a one-line comment or /* */ for a block. Comments explain why a step exists.

How it works

Safely editing a query by hand

  1. 1

    Duplicate first

    Right-click the query and Duplicate it, so you have a working copy to fall back on.

  2. 2

    Open the editor

    Read the code top to bottom and find the step you want to change.

  3. 3

    Make one change

    Edit a single step or insert one new line, keeping the commas right.

  4. 4

    Click Done

    Check the preview and Applied Steps. If something breaks, the error names the step.

  5. 5

    Clean up

    Delete the backup copy once the new version is correct.

See it in code

Walk through the code

powerquery
1let2    // Read the branch file from the shared drive3    Source = Excel.Workbook(File.Contents("D:\Reports\branch_sales.xlsx"), null, true),4    SalesSheet = Source{[Item = "Sales", Kind = "Sheet"]}[Data],5    Promoted = Table.PromoteHeaders(SalesSheet, [PromoteAllScalars = true]),6    /* Trim stray spaces from city names before grouping */7    CleanCity = Table.TransformColumns(Promoted, {{"City", Text.Trim, type text}})8in9    CleanCity

1/4A comment explains the step. The file path is the line you'd fix if the file moves.

A query edited by hand: comments added, and a new CleanCity step written directly in the editor.

Save yourself the pain

Common mistakes

Oops

Adding a new step but forgetting to update the in clause.

Do this instead

If in still names the old last step, your new step is ignored. Always point in at the step you want returned.

Oops

Making big edits with no backup.

Do this instead

Duplicate the query first or copy the code into a text file. Undo inside the editor is limited.

Your mission

Move a query between files

~15 min

Quick check

You added a new step at the bottom of the let block, but the preview doesn't change. What's the likely cause?

Go deeper

  1. 1Copy a query's code into a new blank query.
  2. 2Make a small change by hand, like a filter value.
  3. 3Keep a text file of useful M snippets.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge