Sub topic 10
Verifying results and fixing common problems
This chapter assumes you can build an Import-mode model in Power BI Desktop and edit queries in Power Query. It also assumes you have already created the RangeStart and RangeEnd parameters, filtered a table with them, and defined a refresh policy. Here you check that incremental refresh does what you intended and learn how to diagnose the failures that come up most often.
What "working" means
An incremental refresh setup can publish and refresh without any error and still fail to save you any time. Three things must be true for it to work:
- The filter on
RangeStartandRangeEndfolds to the source, so the source database returns only the rows for each partition. - The service created the partitions you expect: archive partitions that are not refreshed, and incremental partitions that are.
- Each scheduled refresh touches only the incremental partitions, and the row counts and totals match the source.
The checks below follow that order. Start at the source, then check the model, then check the refresh history.
Check 1: confirm that the filter folds
Query folding means Power Query translates your steps into one native query that the source runs. For incremental refresh it matters because each partition refresh sends the date range to the source as a WHERE clause. If folding breaks, Power BI downloads the whole table for every partition and filters it in the mashup engine. That is slower than a plain full refresh.
In Power Query
- Open Power Query Editor in Power BI Desktop.
- Select the table and look at the Applied Steps pane.
- Right-click the step that filters on
RangeStartandRangeEnd. - If View Native Query is enabled, the step folds. If it is greyed out, the step does not fold.
Check the last step in the query as well as the filter step. A step after the filter can break folding for the whole query, even if the filter step folds on its own. When the final step has View Native Query enabled, everything before it folds too.
When the native query is available, look for the date condition in it. It should look similar to this:
select [OrderDate], [DateKey], [Amount]
from [dbo].[FactSales]
where [OrderDate] >= convert(datetime2, '2020-01-01 00:00:00')
and [OrderDate] < convert(datetime2, '2020-02-01 00:00:00')If the where clause is missing, the filter is not being sent to the source.
Sources that have no View Native Query
Some sources, such as flat files, folders, and many web connectors, cannot fold at all. Others can fold, but the menu option is disabled for certain connectors. For these, do not rely on the menu alone. Run a trace on the source (for a SQL source, SQL Profiler, Extended Events, or the query history in the database) while you refresh in Desktop, and read the statements that arrive. A statement that selects the whole table with no date predicate means the filter did not fold.
Common reasons folding breaks
| Cause | What to do |
|---|---|
| A step that the connector cannot translate, such as a custom function, `Table.Buffer`, or an index column added before the filter | Move the date filter to be the first or one of the first steps, before any step that does not fold |
| Changing a column type with a conversion the source cannot do | Do the conversion after the filter, or do it in a view at the source |
| Merging with a query from a different source | Move the join into a source view, or merge after the filter on a table that already has the range applied |
| Filtering a column of a different type than the parameters (for example a `Date` column against `DateTime` parameters) | Match the types, or convert on the parameter side, as in the integer key example from the earlier chapter |
| Filter written with a function that has no SQL equivalent | Use plain comparisons such as `>=` and `<` on the raw column |
A related trap is a native query that you wrote yourself, using Value.NativeQuery. Folding does not continue past a hand-written query unless you pass the EnableFolding option, and even then the query must be a plain SELECT. The simpler route is to put the logic in a view and connect to the view.
Check 2: inspect the partitions
After you publish and run the first refresh in the service, the policy turns into partitions. With a policy of five years of data and ten days of incremental refresh, you expect roughly these:
- One partition for each archived year.
- Partitions for the incremental period, typically one per day, though the service may merge older ones as time passes.
You can see them with a tool that connects through the XMLA endpoint, such as SQL Server Management Studio or Tabular Editor. In SSMS, connect to the workspace with Analysis Services as the server type. Expand the database, then the table, and open Partitions. A query in DAX Studio or SSMS can also list them:
SELECT [Name], [RefreshedTime], [RowsCount]
FROM $SYSTEM.TMSCHEMA_PARTITIONSOther columns in the same view, such as [State] and [Mode], can help when a partition looks odd. Reading partition metadata requires that the workspace is on Premium, Premium Per User, or Fabric capacity with the XMLA endpoint enabled for read. Without that you cannot list partitions, and you must rely on refresh history and data checks instead.
What to look for:
- Partition count matches the policy. A table with no partitions beyond the default one means the policy was not applied. This happens when you republished a model without the policy, or when the table was overwritten by a version that did not have it.
- The incremental partitions have a recent refresh time, and the archive partitions have an old one. If every partition has the same recent time, the service refreshed everything.
- Row counts are plausible. A partition with zero rows for a period you know had sales points to a filter or data problem. A partition far larger than its neighbours may mean a date column with a default value, such as
1900-01-01or9999-12-31, which falls in a boundary partition.
Check 3: read the refresh history
In the service, open the semantic model, choose Refresh history, and compare the first refresh with later ones.
- The first refresh after publishing loads all partitions, so it is the slowest and can run for hours on a big table. This is expected. If that first refresh times out, see the problem list below.
- Later refreshes should be much shorter and should grow with the size of the incremental window, not with the size of the whole table.
If later refreshes take as long as the first one, folding is the most likely cause, followed by a setting that forces a full load. Look at the source's query log during a refresh. Each incremental partition should produce one query with a narrow date range.
Check 4: compare with the source
Fast and error-free is still not correct. Run a few totals in the model and in the source, and compare them:
- Row count and sum of a key measure for a closed historical period, for example last full year.
- The same for the current incremental window.
- The minimum and maximum of the date column in the model.
For historical periods, a mismatch usually means rows outside the policy window changed at the source and nothing refreshed them. Archive partitions are not reloaded, so edits to old rows do not show up. For the incremental window, a mismatch usually means the refresh has not run since the change, or the filter boundaries are wrong.
Common problems and fixes
The first refresh fails or times out
The first refresh must build every partition, so it needs far more time and memory than later ones. Typical fixes:
- Publish with a small policy first, and widen it later. Or lower the archive period until the first refresh succeeds.
- On Premium capacity, the service refreshes partitions in parallel, subject to the capacity limits. Reduce parallelism through the refresh settings, or use the enhanced refresh API, if memory errors occur.
- Use the XMLA endpoint to process partitions in smaller batches, as covered in a later chapter.
- Check source-side timeouts. A command timeout on the source can end a long partition query even when the service is fine.
Duplicate rows
Duplicates mean some rows landed in two partitions. The usual cause is a filter that uses >= on both boundaries, or <= on both. Use >= on RangeStart and < on RangeEnd, never both inclusive. Other causes are a date column whose time part differs between the filter and the source, and a source that inserts a row twice on a date boundary.
Filtered = Table.SelectRows(
FactSales,
each [OrderDate] >= RangeStart and [OrderDate] < RangeEnd
)Missing rows
The opposite problem comes from both boundaries being exclusive, or from filtering a different column than the one the policy uses. Also check time zones: RangeStart and RangeEnd carry no time zone, and partition boundaries are computed from the service's UTC date. If the source stores local time, rows near midnight can appear in a neighbouring partition. That does not lose rows overall, but it affects which partition holds them, and the "complete periods" setting can then make the latest day look incomplete.
The refresh reads the whole table
If the source log shows queries without date predicates, folding is broken. Go back to Check 1. After fixing, republish. Desktop changes to the query do not alter partitions that already exist, but the next refresh uses the new query.
The service complains that the query cannot fold
When a policy is set on a table whose query does not fold, Desktop warns you and the service may reject the refresh depending on settings. Treat the warning as a defect to fix. Do not ignore it because the first refresh happened to work.
Changes to old rows do not appear
Archive partitions are never reloaded by a scheduled refresh. Options:
- Widen the incremental period so it covers how far back changes occur.
- Turn on Detect data changes with a last-modified column, so a changed old partition is refreshed.
- Refresh a specific partition through the XMLA endpoint when a correction is needed.
Republishing wipes the partitions
Publishing a new version of the file from Desktop replaces the model in the service, including the partitions. The next refresh is another full first refresh. If the model is large, avoid republishing for small changes. Edit the model through the XMLA endpoint with a tool such as Tabular Editor, or use deployment pipelines. A published model that has been changed through XMLA can no longer be downloaded as a .pbix file, so keep your source file under version control.
Parameters changed after publishing
RangeStart and RangeEnd values in the service are set by the partitions, not by the values in the file. Editing them in the dataset settings has no useful effect. Their Desktop values only control how much data you load while developing.
A short routine
Use this list after every change to the model or its policy:
- Confirm View Native Query is enabled on the last step of the filtered table.
- Publish, run the first refresh, and note how long it took.
- List partitions and compare the count with the policy.
- Run a second refresh and confirm it is much faster.
- Compare a total for an old period and for the incremental window against the source.
Exercise
A table has an incremental refresh policy that keeps five years and refreshes ten days. The first refresh took four hours. Every later scheduled refresh also takes about four hours, and the source database log shows queries with no WHERE clause on the date column. What is the most likely cause, and what are the first two things you check?
Show answer
The date filter on RangeStart and RangeEnd does not fold, so each partition refresh downloads the whole table and filters it in Power Query. First, in Power Query Editor, right-click the last applied step and check whether View Native Query is enabled. Second, find the first step that disables it, which is often a step placed before the date filter, and move the filter above it or push that step into a source view. Then republish and confirm that the second refresh is much shorter.
Exercise
After the first refresh, the total sales for last March in the model is higher than in the source, and a few orders on the first day of the month appear twice. What is the likely cause in the filter, and what is the correct form?
Show answer
Both boundaries are probably inclusive, so a row exactly on the boundary falls into two adjacent partitions. Use >= on RangeStart and < on RangeEnd, for example each [OrderDate] >= RangeStart and [OrderDate] < RangeEnd. After republishing and running a first refresh, the duplicates should be gone.