M Language Syntax (let and in)
Part of the Power BI Roadmap
In short
Every button you click in Power Query quietly writes a line of M. Once you can read that code, you stop guessing what a query does and start fixing it in seconds.
Every Power Query is an M expression: a let block of named steps, each building on the previous one, and an in clause naming the final result. M is case-sensitive.

Think of it like this
A recipe card with numbered steps
A recipe says: step 1, wash the rice. Step 2, soak the washed rice. Step 3, cook the soaked rice. Each step uses the result of an earlier one, and at the bottom it says "serve step 3". An M query is that card: let lists the named steps, in says which one to serve.
Watch it happen
How a let block builds its result
1/5Source reads the raw CSV of Pune branch sales. Nothing else exists yet.
The big ideas
What you need to know
Steps are named values
Inside let, each line is Name = expression, separated by commas. The last step before in has no comma.
Each step points back
A step usually uses the step before it by name. That chain is what you see in the Applied Steps pane.
M is case-sensitive
Table.SelectRows works, table.selectrows does not. Column names like "amount" and "Amount" are different too.
Names with spaces
A step called Changed Type is written #"Changed Type" in code. Renaming steps without spaces keeps code tidy.
See it in code
Walk through the code
1let2 Source = Csv.Document(File.Contents("C:\Data\pune_sales.csv"), [Delimiter = ",", Encoding = 65001]),3 Promoted = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),4 Typed = Table.TransformColumnTypes(Promoted, {{"OrderDate", type date}, {"Amount", type number}}),5 Filtered = Table.SelectRows(Typed, each [Amount] > 0)6in7 Filtered1/4let opens the block of named steps.
A complete M query: four named steps inside let, and in returns the last one.
Save yourself the pain
Common mistakes
Oops
Leaving a comma after the last step before in.
Do this instead
Commas separate steps, so the final step has none. A trailing comma gives a "Token Identifier expected" error.
Oops
Typing table.selectrows or [amount] in lowercase.
Do this instead
M is case-sensitive. Match function names and column names exactly, including capitals.
Your mission
Read a query line by line
Quick check
In an M query, what decides which table the query finally returns?
Go deeper
- 1Open a query's code and match each line to an Applied Step.
- 2Rename a step in code and watch it update in the steps list.
- 3Note how quoted names like #"Changed Type" are used for steps with spaces.
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.