Sub topic 15
Refresh Behavior and Performance Notes
This chapter assumes you can build append and merge steps, choose a join kind, and read the generated M code. It covers what happens when you refresh a pipeline that combines queries, and how to keep that refresh fast.
What a refresh does
A refresh re-runs every query from its source. Power Query does not store intermediate results between runs. If Sales_2023 and Sales_2024 feed an appended query, refreshing the appended query reads both sources again.
A connection-only query does not load to a sheet, but it still runs whenever a query that depends on it is refreshed. Each loaded query that references it can trigger its own read of the source.
In this layout Clean_Sales may be evaluated once for each loaded query, so the source can be read twice. Power Query can cache some source reads within a single refresh, but you should not rely on that.
Why merges and appends slow down
Appends are usually cheap, because they stack rows without comparing them. Merges cost more, because the engine must match keys between two tables.
These factors have the largest effect:
- Table size. Merging two large tables takes much longer than merging a large table with a small lookup table.
- Key type. Matching on numbers is faster than matching on long text values.
- Fuzzy matching. A fuzzy merge compares similar values, so it is far slower than an exact merge. Use it only when exact matching fails.
- Unneeded columns. Wide tables carry extra data through every step.
- Expanding nested tables. Expanding a column that holds a large nested table can multiply rows, and every later step then processes more data.
Steps that help
- Remove columns before the merge. Use
Table.SelectColumnsor Choose Columns on both sides so the join carries only the columns you need. - Filter rows early. Filter before the merge or append, so later steps handle fewer rows.
- Keep key columns simple. Set the key data type on both sides before merging, and clean text keys as shown earlier.
- Aggregate instead of expanding when you only need a total per key. This avoids creating extra rows.
- Merge against a small table. Put the large table first and the lookup table second, and keep the lookup table limited to the columns and rows you need.
Here is a merge that follows these rules. It trims the customer table to the needed columns before joining.
let
SlimCustomers = Table.SelectColumns(Customers, {"CustomerID", "Name", "Region"}),
Source = Table.NestedJoin(Orders, {"CustomerID"}, SlimCustomers, {"CustomerID"}, "Customers", JoinKind.LeftOuter),
Expanded = Table.ExpandTableColumn(Source, "Customers", {"Name", "Region"}, {"Name", "Region"})
in
ExpandedRefresh settings in Excel
Open Data > Queries & Connections, right-click a query, and choose Properties. These options affect refresh behavior:
| Option | Effect |
|---|---|
| Refresh every N minutes | Refreshes on a timer while the workbook is open. |
| Refresh data when opening the file | Runs the refresh at open, which delays the workbook. |
| Enable background refresh | Lets you keep working while a query runs. |
Refresh All runs all queries, including ones you did not change. If only one query changed, refresh that one.
Failure modes on refresh
A refresh can fail even when the steps worked yesterday. Common causes are:
- A source column was renamed or removed, so a step such as a column expansion no longer finds its column.
- New values in a key column that do not match the lookup table, which produce nulls in the merged columns.
- A source file that moved, or a table that gained extra columns after an append.
After any refresh that changes source data, compare row counts before and after the merge, as described in the verification chapter.
Exercise
A workbook has a large Orders query and a small Customers query. A left outer merge is slow, and you only need Name from Customers. Name two changes that should speed up the refresh.
Show answer
First, remove every column except CustomerID and Name from Customers before the merge, so less data passes through the join. Second, filter Orders to the rows you need before merging, and set CustomerID to the same data type on both sides. Aggregating the nested table instead of expanding it also helps if you need only a summary value.