Fix Power BI "Number of Months" parameter causing incorrect date range calculation #1852
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When users set the "Number of Months" parameter to 3 in Power BI Cost Analysis reports, the report was pulling data from 5 months instead of the expected 4 months (3 closed months + current month). This made it appear that the first 5 days of certain months were missing from the analysis.
Root Cause
The date calculation formula had an off-by-one error with an extra
+1in the month offset:Before (buggy):
After (fixed):
Example
When running the report in October 2024 with
Number of Months = 3:Solution
Removed the incorrect
+1offset from all date calculation formulas across 5 locations in the Power BI datasets:This fix aligns the code with the official documentation:
Testing
This is a pure mathematical correction with no logic changes. Manual validation can be performed by:
Files Changed
src/power-bi/storage/Shared.Dataset/definition/expressions.tmdl(2 changes)src/power-bi/storage/Shared.Dataset/definition/tables/StorageData.tmdl(1 change)src/power-bi/kql/Shared.Dataset/definition/expressions.tmdl(1 change)src/power-bi/kql/Shared.Dataset/definition/tables/StorageData.tmdl(1 change)docs-mslearn/toolkit/changelog.md(documented the fix)Fixes #1833
Original prompt
Fixes #1839
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.