Power Query Fundamentals
The transformations you'll actually use daily
Power Query is a data transformation DSL with a visual UI and M code — merge/append queries, split columns, replace values, add columns, and guard against fragile, hidden steps.
What you will learn
- Perform merge, append, split, replace and custom-column operations
- Read and edit generated M to fix tricky cases
- Document steps so refreshes and audits stay sane
What is this?
Power Query is Power BI's transformation engine: a visual UI over M, a functional language. Everyday operations — merge queries (joins), append (union), split columns, replace values, conditional and custom columns — translate to M expressions that run on the full dataset at every refresh. Understanding M turns 'works now' into 'works forever'.
Why do you need it?
- Merge/append are how you build one model table from many sources.
- The applied-steps model makes every transform auditable and reorderable.
- M is debuggable: see exactly which step corrupted a column.
- Mastering it prevents the silent 'refresh changed my data' disasters.
Mental model
A chef's mise en place checklist
Power Query steps
Each step — wash, cube, blanch — is recorded in order. Skip or reorder and the dish changes. You tweak a step, the whole menu's output shifts predictably, and you can always replay last night's exact procedure.
How it works
- Queries are expressions reducing to a table; applied steps chain M expressions.
- Merge performs a relational join with a chosen kind (left outer, full, inner) and key(s).
- Append stacks tables with matching headers (union semantics).
- Split/conditional/custom columns add or reshape columns via M functions.
- Parameterization makes queries reusable (tables, letters, thresholds).
A Power Query step pipeline: shape, then load.
Examples
M for a merge and a conditional column
let Source = Sql.Database("srv","dw"), Sales = Source{[Schema="gold",Item="fact_sales"]}[Data], Cust = Source{[Schema="gold",Item="dim_customer"]}[Data], Merged = Table.NestedJoin( Sales, {"cust_key"}, Cust, {"cust_key"}, "Cust", JoinKind.LeftOuter), Expanded = Table.ExpandTableColumn(Merged, "Cust", {"region","tier"}), Flagged = Table.AddColumn(Expanded, "is_high_value", each if [amount] >= 500 then "high" else "low")in FlaggedA left join on the customer key, then attributes expanded, then a conditional column — the standard build of a model-ready import.
In production
- A report merges two exported CSVs on an order key to avoid a warehouse round-trip for a small join.
- An appender union's monthly export files, handling header normalization first.
- A parameterized query lets the team switch the target month without editing M by hand.
Best practices
- Do merges on the source or in the model, not in Power Query, when the source can.
- Expand only needed columns from a merge (unchecked lists bloat memory).
- Name steps and keep them lean; every step costs transform time.
- Use parameters over hard-coded literals; document non-obvious logic in the step name.
Common mistakes
- Merging in Power Query when a warehouse view is cheaper — lost folding.
- Expanding all merge columns, doubling memory per refresh.
- Hidden steps (obsolete 'remove other columns') that corrupt later edits.
- Using dynamic column numbers with labels that drift between exports.
Common issues
Append fails on header mismatchOne file's column order/name drifted
Normalize per-file headers (rename/promote) before appending.
Merge multiplies rowsRight-side key not unique
Dedupe the right table or change the join to match grain.
Debugging tips
- Wrong after refresh? Step through Applied Steps and inspect the changed column at each dot.
- Merge duplicates? Check join kind and key uniqueness on the right side.
- Custom column errors visible? Show the error column to find offending rows.
Interview checkpoint
Hands-on lab
- Replicate merge and append in SQLite
- Spot the row-multiplication trap in a merge
- Normalize headers before an append
Merge and Append with M Semantics
40 min · intermediate
Quick quiz
Which operation stacks two tables with the same shape vertically?
Every applied step in Power Query is reversible and reorderable.