Power BI Course
Introduction to Power Query
Power Query is the engine that sits between your raw data sources and your Power BI data model. Every time you clean a column, remove duplicates, or change a data type in Power BI Desktop, you are writing Power Query steps — whether you realise it or not. This lesson explains what Power Query actually is, how it fits into the Power BI workflow, and why understanding it deeply makes every other part of Power BI easier.
What Power Query Does
Raw data from the real world is almost never ready to use. Columns have the wrong names, dates are stored as text, there are blank rows, duplicate entries, inconsistent capitalisation, and values split across columns that should be merged. Power Query is the tool that fixes all of this before the data ever reaches your model or your visuals.
The critical thing to understand is that Power Query never changes your source file. The original Excel file or database table is untouched. Power Query reads the source, applies your transformation steps in memory, and loads the result into the model. If the source file changes tomorrow, Power Query re-reads it and re-applies all your steps automatically on the next refresh.
Power Query vs Other Tools
| Approach | How it works | Problem with it |
|---|---|---|
| Manual Excel editing | Open the file, delete bad rows, fix values by hand, save | You have to redo all of it every time the source file updates. Not repeatable. One mistake breaks everything silently. |
| SQL preprocessing | Write SQL queries that clean and join the data before Power BI sees it | Requires database access and SQL knowledge. Changes need a developer. Business users cannot maintain it themselves. |
| Python/R scripts | Write code to clean data before loading into Power BI | Requires programming knowledge. Hard for non-technical users to read, maintain, or modify. |
| Power Query | Click-based UI that records each transformation as a replayable step. Steps run automatically on every refresh. | None for most use cases. Advanced transformations require writing M code directly. |
Opening the Power Query Editor
You access Power Query through Power BI Desktop — it is not a separate application. There are two ways to open it, and both take you to the same editor window.
The Power Query Editor — Full Layout
|
123 OrderID
|
📅 OrderDate
|
🔤 CustomerID
|
1.2 Revenue
|
🔤 Status
|
|---|---|---|---|---|
| 1001 | 2024-01-05 | C101 | 1200 | Shipped |
| 1002 | 2024-01-18 | C102 | 850 | Delivered |
| 1003 | 2024-02-03 | C103 | 430 | Processing |
| 1004 | 2024-02-14 | C101 | 95 | Shipped |
| 1005 | 2024-03-07 | C104 | 1540 | Delivered |
The Four Zones of the Editor
What Are Applied Steps?
Every action you take in the Power Query Editor is recorded as a step in the Applied Steps list. Steps run from top to bottom every time the query is refreshed. This is the fundamental concept that makes Power Query so powerful — your entire cleaning process is saved, repeatable, and editable.
| # | Step name | What it does | M code generated |
|---|---|---|---|
| 1 | Source | Connects to the data source — file path or database connection | Excel.Workbook(...) |
| 2 | Navigation | Selects the specific sheet or table within the source | Source{[Name="Orders"]}[Data] |
| 3 | Promoted Headers | Promotes first row to column headers | Table.PromoteHeaders(...) |
| 4 | Changed Type | Sets the data type for each column | Table.TransformColumnTypes(...) |
| 5 | Removed Blank Rows | Filters out rows where all values are null | Table.SelectRows(...) |
| 6 | Renamed Columns | Renames columns to clean, consistent names | Table.RenameColumns(...) |
Introduction to M Code
Every Applied Step is stored as a line of M code — the language Power Query runs under the hood. You do not need to write M code to use Power Query effectively, but understanding its basic structure lets you read what your steps are doing, fix errors, and handle transformations that the UI cannot do alone.
Basic M code structure — every query is a let...in expression:
let
// Step 1 — connect to source
Source = Excel.Workbook(File.Contents("C:\Data\Sales.xlsx"), null, true),
// Step 2 — navigate to the Orders sheet
Orders_Sheet = Source{[Item="Orders", Kind="Sheet"]}[Data],
// Step 3 — promote first row to headers
#"Promoted Headers" = Table.PromoteHeaders(Orders_Sheet, [PromoteAllScalars=true]),
// Step 4 — set column data types
#"Changed Type" = Table.TransformColumnTypes(
#"Promoted Headers",
{
{"OrderID", Int64.Type},
{"OrderDate", type date},
{"Revenue", type number},
{"Status", type text}
}
),
// Step 5 — remove blank rows
#"Removed Blank Rows" = Table.SelectRows(
#"Changed Type",
each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))
)
in
// The last step name is what gets loaded into the model
#"Removed Blank Rows"
Close and Apply vs Apply vs Discard
Changes you make in the Power Query Editor are not immediately applied to the model. You control when they take effect using three options in the Home ribbon of the editor.
Teacher's Note: The single biggest mindset shift for Power Query beginners is understanding that you are not editing data — you are writing instructions. Your source file never changes. Every step you add is a replayable instruction that Power BI will re-execute every time you refresh. This means you can always delete a bad step, reorder steps, or start over — the original data is always safe. If you think of Power Query as a recipe that runs on your data, rather than a tool that modifies it, everything else becomes clearer.
Practice
Practice 1 of 3
Every action you take in the Power Query Editor is recorded as a ___ in the Applied Steps list, and these run from top to bottom every time the query is refreshed.
Practice 2 of 3
The underlying language that Power Query uses to store and execute transformation steps is called ___ code.
Practice 3 of 3
When you are done transforming data in the Power Query Editor and want to update the model and close the editor, you click ___ & Apply in the Home ribbon.
Lesson Quiz
Quiz 1 of 3
You apply 12 transformation steps to a query in Power Query and click Close & Apply. The next day the source Excel file is updated with 200 new rows. What happens when you click Refresh in Power BI Desktop?
Quiz 2 of 3
You click a step called "Removed Blank Rows" in the Applied Steps list. The data preview shows the table before blank rows are removed — the blank rows are still visible. What does this tell you?
Quiz 3 of 3
You have been editing queries in the Power Query Editor for 20 minutes and realise you have made several mistakes across multiple steps. You want to discard everything and return to the last saved state. What do you do?
Next up — Lesson 17 goes deep into the Query Editor Layout — every ribbon tab, every right-click menu, and the column header controls that most users never discover.