Module 4 · Power BI Fundamentals
Power Query
Shape data with Power Query - applied steps, types, custom columns, merges - and profile columns to spot problems.
About 20 minutes
The problem
The orders table has quantity, price and discount, but no revenue. You could calculate it later in DAX, but a clean, well-typed revenue column at the source keeps the model simple. Power Query is where data gets shaped before it reaches the model, and every step you take is recorded, so it runs again on every refresh.
The concept
Open it: Home → Transform data. The Power Query Editor shows:
| Area | Purpose |
|---|---|
| Queries pane (left) | One query per table |
| Preview (middle) | The data after all steps so far |
| Applied Steps (right) | Every change, in order. Click a step to see the data at that point; delete a step to undo it |
| Formula bar | The M code for the selected step (View → Formula Bar if hidden) |
Transformations you'll use constantly
| Task | Where |
|---|---|
| Rename a column | Double-click its header |
| Change type | Click the type icon at the left of the header |
| Remove columns | Select → Home → Remove Columns |
| Filter rows | Header drop-down |
| Replace values | Transform → Replace Values |
| Add a calculated column | Add Column → Custom Column |
| Bring columns from another query | Home → Merge Queries (like XLOOKUP) |
| Stack tables with the same columns | Home → Append Queries |
Column profiling. View → Column quality / Column distribution / Column profile show valid, error and empty percentages, distinct counts and value frequencies. By default it profiles only the first 1,000 rows: click "Column profiling based on top 1000 rows" in the status bar and choose the entire data set.
Merge and append
Two transformations combine queries, and they're easy to mix up:
| Merge | Append | |
|---|---|---|
| Adds | Columns from another table | Rows from another table |
| Matches on | A key column in both tables | Column names |
| Like | XLOOKUP, SQL JOIN | Copy-pasting one list under another, SQL UNION ALL |
| Kolanut use | Bring category into orders | Combine monthly order files into one |
A merge asks for a join kind. The ones you'll use:
| Join kind | Keeps | Use for |
|---|---|---|
| Left outer (the default) | Every row of the first table, with matches from the second where they exist | Adding details: every order, with its product's category |
| Inner | Only rows that match in both | Keeping only orders for products in a list |
| Left anti | Rows of the first table with no match | Finding problems: orders whose product_id isn't in products |
A left anti merge is a quick data-quality check: if it returns any rows, some orders point to products that don't exist.
How Power Query records your work
Every click becomes a step written in M, Power Query's language. You rarely type M, but reading it helps:
Power Query (M)
= Table.AddColumn(#"Changed Type", "revenue", each [quantity] * [unit_price] * (1 - [discount_pct] / 100), type number)| Piece | Means |
|---|---|
Table.AddColumn | The function: add a column to a table |
#"Changed Type" | The input: the result of the previous step, by its name |
"revenue" | The new column's name |
each [quantity] * … | The formula, worked out for each row |
type number | The new column's type |
Each step takes the previous step's result and passes its own result on, like a recipe. That's why order matters: delete or move a step and every step after it may break.
Good habits with steps
- Set types early, straight after loading, and check them: a number column typed as text causes problems in every step after.
- Rename steps that matter (right-click → Rename):
Added revenueis clearer thanAdded Customsix months later. - Remove columns you don't need, early. Smaller tables load faster.
- Don't edit in Excel first. Do every change in Power Query, so it repeats on the next refresh instead of being lost.
- Check after each important step: row counts in the status bar, column quality at 100% valid.
Close & Apply (Home) saves your steps and loads the result into the model.
This is the Power Query Editor with Kolanut's three queries:

- Queries pane: one query per table.
- Formula bar: the M code for the selected step.
- Column quality: Valid, Error and Empty percentages for each column.
- Applied Steps: every change, in order.
- Status bar: Column profiling based on top 1000 rows. Click it to profile the whole table.
- The ribbon: Home, Transform and Add Column hold the transformations.
Example
The revenue custom column shown above is exactly what the Custom Column dialog writes for you. In the dialog you only enter:
Power Query (M)
[quantity] * [unit_price] * (1 - [discount_pct] / 100)Walkthrough
Home → Transform data. Select the
ordersquery.View → tick Column quality and Column distribution, then switch profiling to the entire data set. All columns should be 100% valid.
Add Column → Custom Column. Name:
revenue. Formula: as above. OK.
The Custom Column dialog: name (1), formula (2), the column list you can double-click to insert names (3), and the syntax check (4).TapClick the image to see it full size. Click the
ABC123icon on the new column's header → Decimal Number (or Fixed decimal number, good for currency). The result:
The new step's M code (1), the revenue column (2), and the two new Applied Steps (3): Added Custom, then Changed Type1 for the type change.TapClick the image to see it full size. Merge the product category in:
- With
ordersselected, Home → Merge Queries. - Choose
productsas the second table; clickproduct_idin both; Join Kind Left Outer. OK. - A new column of nested tables appears. Click its expand icon (↔), untick all but
category, untick Use original column name as prefix. OK.
- With
Look at Applied Steps: each action is a step, in order.
Home → Close & Apply. Save.
Practice
Practice
Add the revenue custom column, load it, and show its total in a Card. What is total revenue? (A rounded figure is fine.)
Practice
After merging category into orders, how many packs of Snacks were sold in total?
More practice
Optional drills. They don't count towards the certificate, but they're the fastest way to make this lesson stick. Several use a different dataset from the lesson on purpose: if you can do the same thing on unfamiliar data, you've really learned it.
Drill · optional
In Power Query, merge category from products into orders. What is total revenue from Personal care?
Drill · optional
In Power Query, filter the HR leave.csv to approved = Yes only. How many leave days remain in total?
Check your understanding
Answer every question to check.