Power BI Lesson 16 – Introduction to Power Query | Dataplexa
Power Query · Lesson 16

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.

📥
Raw source data
Excel files, CSVs, databases, APIs — exactly as they come. Wrong types, messy headers, blank rows, inconsistent values. Not ready to analyse.
⚙️
Power Query transforms
A recorded sequence of steps that clean and reshape the data. Each step is stored as M code. Steps run automatically every time the data is refreshed.
Clean data model
Correct types, clean values, properly named columns — loaded into the Power BI model and ready for relationships, DAX measures, and 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.

From the Home ribbon
Home → Transform Data → Transform Data. This opens the Power Query Editor showing all currently loaded queries.
Use when: you want to edit any existing query or add new transformations
From the Get Data flow
When connecting to a new data source, the Navigator preview window has a Transform Data button. Clicking it opens the editor immediately instead of loading the raw table straight into the model.
Use when: you want to clean data before the first load

The Power Query Editor — Full Layout

Power Query Editor — SalesReport.pbix
Home
Transform
Add Column
View
Tools
Help
Queries
Orders
Customers
Products
Calendar
4 queries total
= Table.TransformColumnTypes(#"Promoted Headers", {{"OrderID", Int64.Type}, {"OrderDate", type date}, {"Revenue", type number}})
123 OrderID
📅 OrderDate
🔤 CustomerID
1.2 Revenue
🔤 Status
10012024-01-05C1011200Shipped
10022024-01-18C102850Delivered
10032024-02-03C103430Processing
10042024-02-14C10195Shipped
10052024-03-07C1041540Delivered
5 rows · 5 columns · Last refreshed: today
Query Settings
NAME
Orders
Applied Steps
Source
Navigation
Promoted Headers
Changed Type

The Four Zones of the Editor

Queries pane
Left panel
Lists every query (table) in your file. Click any query to preview it in the data grid. Each query is independent — transformations on one do not affect others unless you explicitly reference them. Right-click a query to rename, duplicate, delete, or disable it.
Formula bar
Top centre
Shows the M code for the currently selected Applied Step. Every click-based action you take in the UI — rename a column, filter a row — generates M code here automatically. You can edit this code directly for advanced transformations. This is your window into what Power Query is actually doing.
Data preview
Centre
Shows the first 1,000 rows of the selected query after all steps up to and including the currently selected step have been applied. This is a live preview — clicking a different Applied Step rewinds the preview to show what the data looked like at that point in the transformation sequence.
Query Settings
Right panel
Shows the query name (editable) and the Applied Steps list — the full sequence of transformations recorded for this query. Click any step to preview the data at that point. Right-click a step to rename, delete, or move it. The last step in the list is what gets loaded into the model.

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"
Key M code rules to know
let ... in
Every query is wrapped in a let block (defines steps) and an in block (names the final output step). This is the skeleton of every M query.
Each step references the previous
Each step takes the output of the prior step as its input. "Changed Type" receives "#Promoted Headers" as input. This is why step order matters — moving a step changes what data it receives.
Names with spaces use #"..."
Step names containing spaces must be wrapped in #"..." — e.g. #"Promoted Headers". Single-word names like Source need no quotes. Power BI generates these automatically.
// comments are ignored
You can add // line comments anywhere in M code to document what a step does. They are stripped out at runtime and have no effect on the query result.
The in value is the output
Whatever step name appears after in is what Power BI loads into the model. It is always the last step. Power BI updates this automatically as you add steps.

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.

Close & Apply
Saves all query changes, runs all queries against the source data, loads the results into the model, and closes the editor. Use this when you are done with your transformations and ready to see updated visuals.
Most common choice
Apply
Saves and runs all queries and updates the model, but keeps the Power Query Editor open. Use this when you want to see the effect on your report visuals without closing the editor first.
Keep editor open
Discard Changes
Closes the editor and throws away every change you made since the last Apply. The model reverts to its previous state. Use this if you made a mistake and want to start over from the last saved state.
Undo all changes

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.