Lesson theory
Every Power Query step is a line of M. You can see the whole query in the Advanced Editor (Home › Advanced Editor):
let
Source = Csv.Document(File.Contents("C:\Data\sales.csv"), [Delimiter=",", Encoding=65001]),
Headers = Table.PromoteHeaders(Source),
Typed = Table.TransformColumnTypes(Headers, {{"Amount", type number}}),
PaidOnly = Table.SelectRows(Typed, each [Status] = "Paid"),
Totals = Table.Group(PaidOnly, {"City"}, {{"Amount", each List.Sum([Amount]), type number}})
in
Totals
let … in: the steps are variables, each one refers to the previous; afterincomes the step to return;each [Status] = "Paid"— a short function applied to every row, and[Status]is a field of the current row;- M is case-sensitive:
table.selectrowswon't work, and "Paid" ≠ "paid"; - parameters (Home › Manage Parameters) replace hard-coded values, such as a folder path or a filter threshold;
try [Price] * 1 otherwise 0— catches an error inside an expression.
In the trainer, the formula of each step is shown above the preview; the trainer can't edit M directly.
Test yourself
Enter — commit · F2 — edit · F4 — $ in a reference · Ctrl+C/Ctrl+V — copy and paste · Ctrl+Z — undo
Esc or F6 — leave the sheet for the «Check» button · Shift+Tab in the first cell — back to the page