Power Query course · Lesson 16 of 17

Performance, query folding and refresh options

Make queries refresh faster: query folding and View Native Query, step order, Table.Buffer, loading to the Data Model, and every refresh setting.

Advanced 20 min read

A query that takes three seconds on a sample file can take ten minutes on a full year of data, and a workbook with twenty queries can freeze Excel during Refresh All. Most slow queries are slow for a handful of predictable reasons: too much data travels from the source, the same data is read several times, or the result is loaded somewhere it does not need to go. This lesson explains how Power Query executes steps, how to tell whether the database does the work for you, where to load results, and which refresh settings to use.

How a refresh runs

When you refresh, Power Query starts from the query's last step and works backwards to find what it needs, then reads the sources. Two things follow. First, it streams data where it can: a filter step processes rows as they arrive rather than loading everything first. Second, some steps need all rows before they can return anything: sorting, grouping, pivoting, merging, removing duplicates and Table.Buffer. These are the expensive steps on large data, and their position in the query matters.

Query folding

With sources that understand a query language, mostly databases (SQL Server, Oracle, PostgreSQL, MySQL, Access) and to some extent OData feeds and SharePoint lists, Power Query tries to fold your steps: it translates them into one native query, such as a SQL statement, and lets the server do the work. A filter on Year = 2026 followed by a Group By by region becomes a single SELECT … WHERE … GROUP BY statement, and only a few summary rows travel over the network instead of millions of detail rows.

Usually foldsUsually stops folding
Choose and remove columnsAdding an Index column
Filters on values and datesCustom columns using functions with no SQL equivalent
SortingTable.Buffer
Group By with Sum, Count, Min, Max, AverageMerging with a query from a different source (for example an Excel table)
Merges between tables of the same databaseChanging types with a locale, some text transformations
Simple custom columns with arithmeticKeep or Remove Top/Bottom Rows after non-folding steps

Once a step cannot fold, every step after it runs locally on your computer, even if those later steps could have folded on their own. So the rule is: put foldable steps (column selection, filters, grouping) first, and non-foldable steps (index, complex text work, merges with local tables) as late as possible.

Checking whether a step folds

  1. In the editor, right-click a step in Applied Steps.
  2. If View Native Query is available, the query up to that step folds; click it to see the SQL that will run on the server.
  3. If it is greyed out, folding stopped at or before that step. Walk up the list to find the first step where it becomes greyed out.
Note. Power BI and dataflows show folding indicators next to each step. Excel's editor does not, so View Native Query is your main tool. A greyed-out option is a strong hint but not absolute proof: some sources fold without exposing the native query.
AB
1StepView Native Query
2Source (SQL Server SalesDW)available
3Added Indexgreyed out
4Removed Other Columnsgreyed out
5Filtered Rows (Year = 2026)greyed out
6Grouped Rowsgreyed out

Before: an early Index step breaks folding, so 4 million rows are downloaded and then filtered and grouped on the PC.

AB
1StepView Native Query
2Source (SQL Server SalesDW)available
3Removed Other Columnsavailable
4Filtered Rows (Year = 2026)available
5Grouped Rowsavailable
6Added Indexgreyed out

After: the same steps reordered. The server filters and groups; only the summary rows are downloaded and numbered locally.

Tip. Files (CSV, Excel, folders) never fold. With file sources the same principle still helps: remove unneeded columns and filter rows early, so every later step works on less data.

Avoid reading the same source many times

Each query is evaluated on its own. If five queries reference a Sales_Raw query, Power Query may read the source files five times during Refresh All. Some practical consequences:

  • Prefer one query that cleans the data and several light queries that Reference it, rather than five duplicates that each start from the file.
  • Inside one query, a step used repeatedly, such as a lookup list scanned for every row by a custom function, can be loaded into memory once with Table.Buffer or List.Buffer.
  • Do not buffer by reflex. Buffering stops folding and holds the whole table in memory; use it for small lookup tables used many times, not for the main fact table.
Power Query M
let
    Source = Sales_Clean,
    Rules = Table.Buffer(Keywords),     // small table, read once
    Categorised = Table.AddColumn(Source, "Category", each
        let hits = Table.SelectRows(Rules, (r) => Text.Contains(Text.Upper([Description]), Text.Upper(r[Keyword])))
        in if Table.IsEmpty(hits) then "Other" else hits{0}[Category], type text)
in
    Categorised
Without Table.Buffer the Keywords query could be evaluated again for each of thousands of rows.

Settings that slow the editor

Open File › Options and settings › Query Options (in Excel: Data › Get Data › Query Options).

  • Current Workbook › Data Load › Allow data preview to download in the background: when on, Power Query refreshes previews of all queries while you work. In a heavy workbook, turning it off makes the editor much more responsive.
  • Current Workbook › Data Load › Detect column types and headers for unstructured sources: off means no automatic Changed Type steps; you set types yourself.
  • Current Workbook › Privacy: checking privacy levels costs time when sources are combined. Ignoring them can speed things up, but read the warnings in Getting data: files, folders, tables, web pages and databases first.
  • Global › Data Load › Data Cache Management Options: clear the cache if previews show stale data.

Where to load: sheet, PivotTable, Data Model or nowhere

Choose the destination with Home › Close & Load To… in the editor, or later by right-clicking a query in Data › Queries & Connections and choosing Load To….

DestinationLimitBest for
Table on a worksheet1,048,576 rowsResults people read, filter or use in formulas
PivotTable ReportData stays in the pivot cacheA single summary on one query
Only Create Connection + Data ModelMillions of rows, compressedLarge fact tables, relationships, DAX measures
Only Create ConnectionNothing loadedStaging, helper and parameter queries

Loading two million rows to a sheet is impossible (and 500,000 rows is already slow to save and open). Loading them to the Data Model is routine: the model compresses columns, typically to a fraction of the CSV size, and PivotTables built on it stay fast. See Power Pivot and the Data Model: relationships and DAX measures for relationships and measures.

Watch out. Every query that loads somewhere costs refresh time. Set staging queries (the pieces you append or merge) to Only Create Connection. In the Queries pane, a query not loaded anywhere appears in italics.

Refresh commands and options

ActionHow
Refresh everythingData › Refresh All, or Ctrl+Alt+F5
Refresh one queryRight-click it in Queries & Connections › Refresh, or select its table and choose Data › Refresh All › Refresh (Alt+F5)
Refresh the preview in the editorHome › Refresh Preview
Cancel a running refreshClick the refresh message in the status bar or in Queries & Connections
See what depends on whatIn the editor: View › Query Dependencies

Per-query settings live in Query Properties: right-click the query in Queries & Connections and choose Properties…. On the Usage tab you find:

  • Enable background refresh: you can keep working while it runs. Turn it off when a macro must wait for the refresh to finish.
  • Refresh every N minutes: for dashboards that watch a live database. Do not use it with large file sources.
  • Refresh data when opening the file: opening the workbook always shows current data. Combine with Remove data from the external data range before saving the workbook to keep the file small.
  • Refresh this connection on Refresh All: untick it for archival or very slow queries you want to refresh only on demand.
  • Enable Fast Data Load (on the query's properties in the editor): loads faster but keeps Excel busy until the load finishes.
Tip. For a refresh you can trigger with one button, a one-line macro ThisWorkbook.RefreshAll is enough (see Your first macro: Sub, MsgBox, running it and a button). With background refresh off, the macro waits until all queries finish, so it can safely format or export the result afterwards.

Refresh on Mac and on the web

Microsoft 365 for Mac refreshes queries with supported sources, using Data › Refresh All. Excel for the web can refresh queries whose sources are reachable from the cloud, such as tables in the workbook and files on SharePoint or OneDrive; queries that read local paths, on-premises databases without a gateway, or unsupported connectors cannot be refreshed there. If a workbook must refresh for everyone in a browser, keep its sources in the cloud.

A performance checklist

  1. Remove columns you do not need in the first steps.
  2. Filter rows as early as possible; on databases, keep those steps foldable.
  3. Group before merging when you only need totals from the second table.
  4. Merge on clean, typed, unique keys; remove duplicates in lookup tables first.
  5. Load large tables to the Data Model, not to sheets; set helpers to connection only.
  6. Buffer small lookup tables used by row-by-row functions.
  7. Turn off background previews in heavy workbooks.
  8. Sort only at the end, and only if the output order matters.

Check yourself

1. What is query folding?

2. An Index column is added right after Source on a SQL table. What happens to the filters after it?

3. How can you check in Excel whether a step folds?

4. Where should a 3-million-row fact table be loaded?

5. Which setting shows current data every time the file is opened?