Sub topic 2
Filtering the Table with RangeStart and RangeEnd
Assume you can connect to a relational source in Power BI Desktop and understand Power Query steps. You also need a date or datetime column on the large table.
Apply a folding filter
RangeStart and RangeEnd are Date/Time parameters. The filter keeps rows from the start boundary up to, but not including, the end boundary. This prevents a row from appearing in two partitions.
let
Source = Sql.Database(
"myserver.database.windows.net",
"SalesDb"
),
FactSales = Source{[Schema = "dbo", Item = "FactSales"]}[Data],
Filtered = Table.SelectRows(
FactSales,
each [OrderDate] >= RangeStart
and [OrderDate] < RangeEnd
)
in
FilteredQuery folding means Power Query translates a step into the source system's query language. In this example, the source can execute a filter similar to:
WHERE OrderDate >= @RangeStart
AND OrderDate < @RangeEndFolding matters because Power BI should ask the source for only the required date range. If Power Query downloads the entire table before filtering, incremental refresh cannot reduce the source work effectively.
If the source uses an integer date key such as 20240131, convert the parameters to matching integers before filtering. Do not compare a Date/Time value directly with an integer key.
Define the refresh policy
After the filter works, select the table in Power BI Desktop and configure Incremental refresh. Set:
- An archive period, such as five years, to keep in the model.
- An incremental refresh period, such as the last ten days, to reload.
- Optional settings for detecting data changes or refreshing only complete periods.
The archive period determines how much history the model retains. The incremental period determines which recent data Power BI processes on each refresh.
Understand the resulting partitions
A partition is a separately stored slice of a table. After publishing, the Power BI service evaluates the policy and creates date-based partitions. Older partitions are retained, while recent partitions are refreshed.
The first service refresh usually creates the partitions and loads the configured history. Later refreshes process only the recent partitions, unless the policy or source data requires more work.
Exercise
Why should the filter use [OrderDate] >= RangeStart and [OrderDate] < RangeEnd instead of including both boundaries?
Show answer
The half-open range prevents the same row from belonging to two adjacent partitions.