Sub topic 8
Detecting Data Changes to Skip Unchanged Partitions
An incremental refresh policy limits a refresh to the partitions inside the incremental period. If that period is 10 days, every refresh still reloads 10 daily partitions, even when the source changed in only one of them. Detect data changes removes that waste. Power BI checks each partition in the incremental period with a cheap query and reloads it only when the source data has changed.
This chapter assumes you have already created RangeStart and RangeEnd, filtered a table with them, and defined a refresh policy. It also assumes you have published the model and understand that the policy produces partitions.
What the Feature Does
Without detect data changes, a scheduled refresh runs one data query for each partition in the incremental period. With it, the service runs a second, smaller query first. This is the polling query, and it returns one value for each partition: the maximum of a "last modified" column over that partition's date range.
After a successful refresh, the service stores that maximum value with the partition. This stored value is called a bookmark. On the next refresh, the service runs the polling query again and compares the result with the bookmark.
- If the values are equal, the partition is skipped. No data query runs for it.
- If the values differ, the partition is refreshed in full and the new maximum is stored.
Only partitions in the incremental period are polled. Partitions in the archive period are never refreshed by a scheduled refresh, so there is nothing to skip.
The granularity of the skip is one partition. If a single row changes inside a daily partition, the whole day is reloaded. This is why the granularity you chose for the incremental period matters. Monthly partitions reload more rows per change than daily ones.
Requirements for the Change Column
You pick the column in the incremental refresh dialog in Power BI Desktop, under the option Detect data changes. The column has to meet these conditions:
- It must have the Date/Time type.
- It must not be the same column you filter with
RangeStartandRangeEnd. The partitioning column describes when a business event happened. The change column describes when the row was last written. - The source must update it reliably on every insert and update.
The last condition matters most, because Power BI cannot see changes your source does not record. A column such as LastUpdated that is set by the ETL job, a trigger, or the application on every write works well. A column that is set once at insert and never touched again will hide updates, and the affected partitions will silently go stale.
A typical source table might look like this:
| Column | Type | Role |
|---|---|---|
| `OrderDate` | datetime | Filtered by `RangeStart` and `RangeEnd`. Drives partitioning. |
| `LastUpdated` | datetime | Chosen in **Detect data changes**. Must change whenever the row changes. |
| `DateKey` | int | Optional yyyymmdd key. It cannot serve as the change column. |
Setting It Up in Desktop
- Right-click the table in the Data pane and choose Incremental refresh.
- Turn on incremental refresh and set the archive and incremental periods as you did before.
- Select Detect data changes.
- Choose the
LastUpdatedcolumn from the drop-down list. - Apply the settings and publish.
Desktop does not run the polling query while you develop. The bookmarks exist only in the service, so detection starts to matter only after publishing. The first refresh in the service has no bookmarks yet, so it loads every partition and stores the first maximum values. The second and later refreshes are the ones that skip partitions.
The Polling Query and Query Folding
The polling query is generated from your table's query. For the FactSales table used in this tutorial, it is equivalent to this:
let
Source = Sql.Database("myserver.database.windows.net", "SalesDb"),
FactSales = Source{[Schema = "dbo", Item = "FactSales"]}[Data],
InRange = Table.SelectRows(
FactSales,
each [OrderDate] >= RangeStart and [OrderDate] < RangeEnd
),
MaxUpdated = List.Max(InRange[LastUpdated])
in
MaxUpdatedThe service runs this once per partition, with RangeStart and RangeEnd set to that partition's boundaries. On a SQL source the query folds into a statement of roughly this shape:
SELECT MAX([LastUpdated])
FROM [dbo].[FactSales]
WHERE [OrderDate] >= @start AND [OrderDate] < @endThis is why folding still matters here. The statement is cheap only when the source can evaluate it, ideally with an index that covers OrderDate and LastUpdated. If the filter does not fold, each polling query reads the whole table and the feature makes refreshes slower, not faster. Everything in the chapter on query folding applies to the polling query as well.
Custom Polling Expressions
The default polling query takes the maximum of one column. Sometimes that is not enough. For example, the source may keep change information in a separate audit table, or you may need to detect deletes. In these cases you can supply your own polling expression through the XMLA endpoint, using a tool that edits the model metadata, such as Tabular Editor or SQL Server Management Studio scripting.
The polling expression is stored in the refresh policy of the table:
{
"refreshPolicy": {
"policyType": "basic",
"rollingWindowGranularity": "year",
"rollingWindowPeriods": 5,
"incrementalGranularity": "day",
"incrementalPeriods": 10,
"pollingExpression": "let\n Source = Sql.Database(\"myserver.database.windows.net\", \"SalesDb\"),\n Audit = Source{[Schema = \"dbo\", Item = \"SalesAudit\"]}[Data],\n InRange = Table.SelectRows(Audit, each [ChangedOn] >= RangeStart and [ChangedOn] < RangeEnd),\n MaxChanged = List.Max(InRange[ChangedOn])\nin\n MaxChanged"
}
}The expression has to return a single value, and the service compares that value with the previous one for equality. It must use RangeStart and RangeEnd so each partition gets its own answer. Test the expression in Power Query first, and confirm that it folds, before you put it into the policy.
A custom expression is also how you handle deletes. A max-of-modified-date check does not notice a deleted row, because the row's timestamp disappears with it. Common workarounds:
- Use soft deletes. Set an
IsDeletedflag and updateLastUpdatedinstead of removing the row. Filter deleted rows out later in the model. - Poll an audit or change-tracking table that records deletions with their own timestamp.
- Return a combined value, such as the maximum timestamp together with a row count, so a deletion changes the result.
When It Helps and When It Does Not
The feature pays off when most partitions in the incremental period do not change between refreshes. Late-arriving corrections to old days are a typical case. The incremental period must be long enough to catch those corrections, but most of its days stay quiet.
It helps less in these situations:
- The incremental period is short, such as one or two days, and the source changes in all of them. Polling then adds queries without removing any.
- Every row is touched on each load, for example when a nightly job rewrites
LastUpdatedfor the whole table. Every polling value changes, so every partition reloads. - The source is slow to answer even a
MAXquery, because the table has no suitable index.
A useful rule is to compare the cost of one polling query with the cost of one data query for the same partition. Polling pays off when it is much cheaper and a meaningful share of partitions end up skipped.
Interaction with Other Settings
Detect data changes combines with the other refresh policy options in these ways:
- Only refresh complete periods. This option decides which partitions are eligible. A partition for an unfinished day is left out. Detect data changes then decides, among the eligible partitions, which ones need reloading. The two settings work at different levels and can be used together.
- Hybrid tables. The DirectQuery partition always reads the source live, so it is not polled or bookmarked. Polling applies to the Import partitions in the incremental period.
- Policy changes. If you change the policy and republish, the service may rebuild partitions. Bookmarks for rebuilt partitions are lost, so the next refresh loads them in full. Expect a longer refresh after a policy change.
- Time zones. The change column is compared as a plain value. If your ETL writes local times in some runs and UTC in others, an update can produce a value that is not larger, or even smaller, than before. Because the check is equality and not "greater than", a different value still triggers a reload, but mixed time zones can make a real change appear identical. Keep the column consistent.
Verifying That Partitions Are Skipped
Look at the refresh in two places.
First, check the refresh history in the service. A refresh that skips most partitions should take noticeably less time than the first one. The duration alone does not prove which partitions were skipped.
Second, connect through the XMLA endpoint with SQL Server Management Studio and view the partitions of the table. The last processed time of each partition shows which ones were reloaded in the latest refresh. Partitions that were skipped keep their earlier time. A trace of the source, such as query history on the database, also shows the polling MAX statements next to the data queries for the partitions that changed.
If every partition in the incremental period reloads on every refresh, check these causes in order:
- The change column is rewritten for all rows on each load.
- The polling query does not fold, so it is slow, or it runs against an unexpected table.
- The model was republished with changes that rebuilt the partitions.
- The change column has the wrong type, or contains
nullfor all rows in a range, so no stable maximum is returned.
Summary of the Decision
| Question | If yes | If no |
|---|---|---|
| Does the source set a Date/Time column on every insert and update? | Detect data changes is a good fit. | Fix the source first, or skip the feature. |
| Do rows get deleted without a trace? | Use soft deletes or a custom polling expression. | The default polling query is enough. |
| Do most partitions in the incremental period stay unchanged? | Expect a clear saving. | The saving is small. |
| Does the polling query fold? | Polling is cheap. | Fix folding before enabling it. |
Exercise
A table is partitioned by OrderDate, with an incremental period of 7 days and detect data changes enabled on LastUpdated. A nightly job deletes a cancelled order from three days ago and does not touch any other row. After the next scheduled refresh, the deleted order is still in the report. Why, and what are two ways to fix it?
Show answer
The polling query returns the maximum LastUpdated for the partition. Deleting a row removes its timestamp but does not raise the maximum, so the value equals the bookmark and the partition is skipped. The fix is to avoid physical deletes, so the job sets an IsDeleted flag and updates LastUpdated, or to use a custom polling expression that also notices deletions, for example by polling an audit table or returning the row count with the maximum timestamp.
Exercise
You enable detect data changes and choose OrderDate, the same column used with RangeStart and RangeEnd, as the change column. What happens, and what should you pick instead?
Show answer
Power BI does not allow the partitioning column to double as the change column. Even if it did, the order date does not change when a row is edited, so edits would never be detected. Pick a column that the source updates on every write, such as LastUpdated or ModifiedOn, with the Date/Time type.
Exercise
After publishing, the first refresh loads every partition and the second refresh skips most of them. Explain why the first refresh cannot skip anything.
Show answer
Skipping depends on a stored bookmark, the maximum change value recorded after a previous successful refresh of the partition. Before the first refresh in the service no bookmarks exist, so there is nothing to compare with. The first refresh loads every partition and stores the first bookmarks.