Forum Discussion
How to set up incremental refresh based on custom conditions?
I have a model that contains both actuals and plan data. I want to set up incremental refresh for the plan data. However, the plan data includes the current year plus five future years, which makes it tricky. Additionally, I want the refresh to be based on the Plan_Category field.
The Plan_Category field contains forecast and budget versions, for example:
00_12_FCST, 01_11_FCST, 02_10_FCST, 03_09_FCST, 04_08_FCST, 05_07_FCST, FCST_WRKG, BDGT_WRKG, BDGT_PRIM1.
I don’t need to refresh all forecast versions every day (e.g., 00_12_FCST, 01_11_FCST, 02_10_FCST, 03_09_FCST, 04_08_FCST, 05_07_FCST). Each forecast version is loaded during a specific time frame, so I only need to refresh a particular version during its designated time frame.
Also FCST_WRKG, BDGT_WRKG, and BDGT_PRIM1, which need to refresh every day. All plan category versions have full-year data (January to December). Some versions may include two full years of data, while others may include up to five full years.
Example:
If plan_category = ‘01_11_FCST and current date between 3/15/current year and 4/1/current year then refresh
If plan_category = ‘02_10_FCST and current date between 4/15/current year and 5/1/current year then refresh
else
refresh – this includes FCST_WRKG, BDGT_WRKG, BDGT_PRIM1 versions
My Data looks like this:
What is the best way to set up incremental refresh based on this condition?
Hi UBP,
Did you manage to run the incremental to see if it worked? I think the logic should be correct.
Thinking your dataset as being stored in two types of "boxes" (partitions):- Archived Partitions (e.g., last 3 years): This contains all your historical data (e.g., data for 01_11_FCST that was loaded in March). During a refresh, Power BI does not touch, query, or delete this data. It is safe.
- Refresh Partition (e.g., last 10 days): This is the only "box" your M script runs against. Power BI completely replaces this partition every day.
Your M script correctly tells Power BI how to build that new "Refresh Partition" efficiently.
How Your Script Works Correctly:
- On 20th March: The script tells Power BI, "For the last 10 days, query the source for FCST_WRKG AND 01_11_FCST." This data is loaded into the model.
- On 5th May: The script tells Power BI, "For the last 10 days, query the source for FCST_WRKG AND 02_10_FCST."
At this point, the data for 01_11_FCST (loaded in March) is now in an archived partition. It is no longer in the 10-day refresh window, so it is safe and will not be deleted.
Your script is performing exactly as intended: it is preventing Power BI from wasting time querying the data source for 01_11_FCST data in May, because you have correctly told it that no new data for that category exists. You are not losing data; you are just performing an efficient, conditional query for the newest partition.
The Final M Script (British English Comments)
This is the correct script to use in your Power Query transformation *before* applying the incremental refresh policy.
let // Connect to your data source Source = YourDataConnectionSource, // 1. Define categories that must refresh daily DailyRefreshList = {"FCST_WRKG", "BDGT_WRKG", "BDGT_PRIM1"}, // 2. Get the current date to determine conditional logic CurrentDate = Date.From(DateTime.LocalNow()), CurrentYear = Date.Year(CurrentDate), // 3. Determine which special forecast to include in the query TODAY ForecastToIncludeToday = if CurrentDate >= #date(CurrentYear, 3, 15) and CurrentDate <= #date(CurrentYear, 4, 1) then "01_11_FCST" else if CurrentDate >= #date(CurrentYear, 4, 15) and CurrentDate <= #date(CurrentYear, 5, 1) then "02_10_FCST" // ... add other 'else if' conditions here else null, // 4. Build the final list of categories to query at the source CategoriesToKeep = DailyRefreshList & List.RemoveNulls({ForecastToIncludeToday}), // 5. CRUCIAL: Filter the SOURCE data based on the categories to refresh today. // This step is highly efficient and (if possible) will be "Query Folded" // (e.g., becoming a WHERE clause in SQL). FilteredByCategory = Table.SelectRows(Source, each List.Contains(CategoriesToKeep, [Plan_Category]) ), // 6. FINAL: Apply the standard Incremental Refresh date filter. // Power BI manages the RangeStart and RangeEnd parameters. FilteredByDate = Table.SelectRows(FilteredByCategory, each [Plan_Date] >= RangeStart and [Plan_Date] < RangeEnd ) in FilteredByDate✅ If this response solved your problem, please mark it as correct to help other community members.
11 Replies
- ajaybabuinturi
Super User
Hi UBP,
I would like to let know that seeting up incremental refresh policy is not possible based on specific Plan_Category field.
I would suggest you that you can create a separate files for specific Plan_Category based on Refresh priority. In this way we can able set up incremental refresh policy. I belive it won't pick up the future values or else you can restrict the future values in SQL by using WHERE clause date < Today -1.Thanks,
If you found this solution helpful, please consider giving it a Like👍 and marking it as Accepted Solution✔. This helps improve visibility for others who may be encountering/facing same questions/issues.- UBPRegular Visitor
Thank you for your response.
Yes, incremental refresh policy is only possible based on date fields, not text or numeric columns.
I didn’t understand the point about using a specific Plan_Category based on refresh priority in a separate file.
Also, I need future years’ data to remain in my model.
- Zanqueta
Super User
Hi UBP,
To configure incremental refresh based on custom conditions such as the Plan_Category field, it is necessary to combine Power BI’s native incremental refresh functionality with conditional logic implemented in Power Query. Although incremental refresh is designed to operate on date fields, it is possible to filter data dynamically using category-specific rules.
Step-by-Step Configuration
1. Define Required Parameters
In Power Query, create two parameters:- RangeStart (type: DateTime)
- RangeEnd (type: DateTime)
These parameters are mandatory for enabling incremental refresh in Power BI.2. Apply Conditional Filtering in Power Query
Below is an example of M code that filters the dataset based on the current date and the Plan_Category field:let Source = ... , // your original table CurrentDate = DateTime.Date(DateTime.LocalNow()), FilteredData = Table.SelectRows(Source, each ( // Categories that must always be refreshed List.Contains({"FCST_WRKG", "BDGT_WRKG", "BDGT_PRIM1"}, [Plan_Category]) ) or ( [Plan_Category] = "01_11_FCST" and CurrentDate >= #date(Date.Year(CurrentDate), 3, 15) and CurrentDate <= #date(Date.Year(CurrentDate), 4, 1) ) or ( [Plan_Category] = "02_10_FCST" and CurrentDate >= #date(Date.Year(CurrentDate), 4, 15) and CurrentDate <= #date(Date.Year(CurrentDate), 5, 1) ) ), // Apply date range filter for incremental refresh DateFilteredData = Table.SelectRows(FilteredData, each [Plan_Date] >= RangeStart and [Plan_Date] < RangeEnd ) in DateFilteredDataReplace [Plan_Date] with the appropriate date field in your dataset that represents the plan period.
3. Configure Incremental Refresh in Power BI Desktop
- Select the relevant table → Modelling → Incremental Refresh.
- Enable incremental refresh and specify the retention period.
- Power BI will use the RangeStart and RangeEnd parameters to apply the date filter.
Official Documentation
For further reference, consult the Microsoft documentation:
https://learn.microsoft.com/en-us/power-bi/connect-data/incremental-refresh-overview✅ If this response resolved your issue, please mark it as correct to assist other members of the community.- UBPRegular Visitor
Thank you for your response.
This will filter out plan_category versions when the current date does not fall within the specified period.
I would like to keep all rows but only refresh certain plan_category versions during incremental refresh.Additionally, the plan data contains future five years of data, which needs to remain in the model and be refreshed as well.
- Zanqueta
Super User
Hello UBP, thank you for feedback.
All right, let us consider an alternative approach. Try applying the code below:
1. Define Required Parameters
In Power Query, create the following parameters, such as :RangeStart = #datetime(2025, 1, 1, 0, 0, 0), RangeEnd = #datetime(2026, 1, 1, 0, 0, 0)
These are mandatory for enabling incremental refresh.
2. Add a Conditional Flag Column
Use the following M code to add a column that flags whether a row should be refreshed:let Source = ... , // your original table CurrentDate = DateTime.Date(DateTime.LocalNow()), AddRefreshFlag = Table.AddColumn(Source, "RefreshFlag", each if List.Contains({"FCST_WRKG", "BDGT_WRKG", "BDGT_PRIM1"}, [Plan_Category]) then true else if [Plan_Category] = "01_11_FCST" and CurrentDate >= #date(Date.Year(CurrentDate), 3, 15) and CurrentDate <= #date(Date.Year(CurrentDate), 4, 1) then true else if [Plan_Category] = "02_10_FCST" and CurrentDate >= #date(Date.Year(CurrentDate), 4, 15) and CurrentDate <= #date(Date.Year(CurrentDate), 5, 1) then true else false ), // Apply date filter only to rows flagged for refresh FilterForIncremental = Table.SelectRows(AddRefreshFlag, each ([Plan_Date] >= RangeStart and [Plan_Date] < RangeEnd and [RefreshFlag] = true) or [RefreshFlag] = false ) in FilterForIncrementalReplace [Plan_Date] with the appropriate date field representing the plan period.
This approach ensures that:- All data remains in the model, including future years.
- Incremental refresh is applied only to relevant rows, based on business rules.
- No data is permanently excluded during the Power Query transformation.
✅ If this response resolved your issue, please mark it as correct to assist other members of the community.
- AnonymousNot applicable
Hello UBP,
I would also take a moment to thank Zanqueta , ajaybabuinturi for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.
Regards,
Community Support Team.- AnonymousNot applicable
Hi UBP,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We are always here to support you.
Regards,
Community Support Team.