Your query is a recipe
You built a report, it worked, and then a refresh slowed to a crawl or a total came out wrong. Before cleaning any data, you need to know how Power Query does its work.
Power Query does not keep the clicks you make. It writes down steps. Each click adds a line to a script in the M language, and the Applied Steps list (in the Query Settings pane, which you reopen with View > Query Settings) shows that script as a list of steps. On every refresh Power Query runs the whole recipe again from the top, against whatever data is in the source that day. That's why the order of the steps and the way you edit them matter.
(Checked against Microsoft Learn's Power Query documentation on 20 October 2026. Nothing in this lesson is a preview feature.)
The sample: a sales query against SQL Server
You connect Power BI Desktop to a SQL Server table dbo.Sales (about 2 million rows: OrderID, OrderDate, CustomerName, Region, Amount). After a few clicks, Home > Advanced Editor shows this:
let
// Source: connect to the server and database
Source = Sql.Database("sql01", "SalesDB"),
// Navigation: pick the table
Navigation = Source{[Schema = "dbo", Item = "Sales"]}[Data],
// Tidy names: Proper-case every customer name ("ACME LTD" -> "Acme Ltd")
#"Capitalized Each Word" = Table.TransformColumns(Navigation, {{"CustomerName", Text.Proper, type text}}),
// Keep only the columns the report needs
#"Removed Other Columns" = Table.SelectColumns(#"Capitalized Each Word", {"OrderDate", "CustomerName", "Region", "Amount"}),
// Keep only the North region
#"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each [Region] = "North")
in
#"Filtered Rows"
Each step takes the step before it as its input: Table.SelectRows(#"Removed Other Columns", ...). That chain is the key to editing safely. Names with spaces get wrapped in #"...". That's ordinary M syntax for a quoted name, nothing to worry about.
Editing steps without breaking the chain
Right-click a step to see what you can do with it:
- Rename: change
Filtered RowstoNorth only. The editor updates every reference to it in the script, so nothing breaks. Use Properties to add a description as well, which shows as a tooltip in Desktop. - Delete (or the X next to the step): the next step is pointed at the step before the one you deleted. Delete until end removes the selected step and every step after it.
- Move before / Move after, or drag and drop: change the order.
- Insert step after: add a step partway through the query. Power Query asks you to confirm.
Gotcha: deleting or moving a step is safe only if no later step depends on what it made. Suppose an earlier
Renamed Columnsstep turnedCustintoCustomerName. Delete it, andRemoved Other Columnsfails with an error saying the columnCustomerNamewasn't found. Click the last step after every edit. The preview pane runs the query up to the step you've selected, so a problem shows up straight away.
Query folding: send the work back to the source
When the source is a database, Power Query tries to translate your steps into the database's own language, SQL for SQL Server, and let the database do the work. That's query folding. There are three possible outcomes:
| Outcome | What happens |
|---|---|
| Full folding | The source runs every step and sends back only the finished rows |
| Partial folding | The source runs the early steps and Power Query runs the rest locally |
| No folding | The source sends everything and Power Query does all the work |
Files have no query engine, so a CSV or Excel source never folds. Everything you do to a CSV runs on your machine.
Why it matters: Microsoft's own example of a "last 10 sales" query against a 3.6 million row table took 361 seconds with no folding and 31 seconds when the query folded completely.
Seeing which steps fold
In Power BI Desktop: right-click a step and choose View Native Query. If you can click it, the query up to that step folds, and you can read the SQL. If it's greyed out, something up to that step doesn't fold. Two warnings: a greyed-out option doesn't mean nothing folds, and some connectors (OData, for example) never offer this option even when they do fold.
In Power Query Online (dataflows and the web editors): every step has a query folding indicator beside it, showing Folding, Not folding, Might fold, Opaque or Unknown, and you can right-click a step and choose View query plan. These indicators are not in Power Query Desktop.
Fix it: move the step that stops folding to the end
In our sample, Capitalized Each Word (Text.Proper) never folds. Because it comes straight after Navigation, every step after it runs locally too. All 2 million rows come down the wire and only then get filtered to North.
The fix: right-click Capitalized Each Word and choose Move after until it's the last step (or drag it there):
#"Removed Other Columns" = Table.SelectColumns(Navigation, {"OrderDate", "CustomerName", "Region", "Amount"}), // folds
#"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each [Region] = "North"), // folds
#"Capitalized Each Word" = Table.TransformColumns(#"Filtered Rows", {{"CustomerName", Text.Proper, type text}}) // local, but now on far fewer rows
Check: right-click Filtered Rows and choose View Native Query. You should see SQL roughly like this:
select [OrderDate], [CustomerName], [Region], [Amount]
from [dbo].[Sales]
where [Region] = 'North'
Right-click Capitalized Each Word: the option is greyed out. That's fine. The heavy lifting has already folded, and Power Query only proper-cases the North rows.
Best practice: put steps that fold (choose columns, filter rows, sort, keep top rows) first, and steps that stop folding last. Moving a step is only safe if the result is the same. Here it is, because filtering on
Regiondoesn't depend on how the customer names are capitalised.
Key takeaways
- Applied Steps are a recorded recipe in M that runs again from the top on every refresh. Each step takes the step before it as its input.
- Renaming a step is safe because references update automatically. Deleting or moving a step can break later steps that depend on its columns, so check the last step after every edit.
- Query folding sends your steps to the source as its own query. Databases can fold; CSV and Excel files can't.
- In Desktop, use View Native Query. In Power Query Online, use the folding indicators and the query plan.
- Steps after one that stops folding usually run locally too. Do the steps that fold first and push steps like Capitalize Each Word to the end.