Repository navigation
Guard monthly cost change against a zero prior month - #2324
Closed
Roland Krummenacher (RolandKrummenacher) wants to merge 1 commit into
Closed
Roland Krummenacher (RolandKrummenacher) wants to merge 1 commit into
Roland Krummenacher (RolandKrummenacher) wants to merge 1 commit into
Conversation
isempty() is false for 0.0, so the existing guard only covers the first row, where prev() returns null. A month whose prior month summed to exactly zero falls through and KQL evaluates x / 0.0 to inf rather than raising an error, so the result reaches the caller as an infinity. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Roland Krummenacher (RolandKrummenacher)
requested review from
Brett Wilson (MSBrett) and
Michael Flanakin (flanakin)
as code owners
September 16, 2026 12:57
Copilot started reviewing on behalf of
Roland Krummenacher (RolandKrummenacher)
September 16, 2026 12:58
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The zero-denominator cases are addressed without affecting existing behavior.
Pull request overview
Fixes infinite monthly cost-change percentages when the previous month’s cost is zero.
Changes:
- Adds zero-value guards for billed and effective cost calculations.
- Preserves existing behavior for null and nonzero prior values.
File summaries
| File | Description |
|---|---|
src/queries/catalog/monthly-cost-change-percentage.kql |
Prevents division by zero in monthly cost percentage calculations. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Collaborator
Author
|
Superseded by #2327 — same commit, but on a branch in this repo rather than my fork, to match the convention used by the other PRs here and so CI and maintainer pushes work normally. Closing this one to avoid a duplicate review. |
Roland Krummenacher (RolandKrummenacher)
requested a deployment
to
ftk-fork
September 16, 2026 13:13 — with
GitHub Actions
Waiting
Roland Krummenacher (RolandKrummenacher)
deleted the
fix/monthly-cost-change-divide-by-zero
branch
September 16, 2026 13:13
|
All Contributors (@all-contributors) please add Roland Krummenacher (@RolandKrummenacher) for code |
Contributor
|
@microsoft-github-policy-service[bot] Roland Krummenacher (@RolandKrummenacher) already contributed before to code |
This branch is waiting to be deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2323.
🛠️ Changes
monthly-cost-change-percentage.kqlguards its division withisempty(PreviousBilledCost). That covers the nullprev()returns on the first row, butisempty()is false for0.0, so a prior month of exactly zero falls through — and KQL evaluatesx / 0.0asinfrather than raising, so the infinity is returned as the percentage.Both guards now also test for zero:
The
== 0.0form matches the convention already used inservice-price-benchmarking.kql.A zero prior month is reachable rather than theoretical:
BilledCostis zero on usage rows covered by a commitment discount, since the charge was billed at purchase time and the amortized amount lands inEffectiveCost. A scope whose month is entirely commitment-covered therefore sumsBilledCostto exactly zero.✅ Verification
Run against the pipeline's shape, so no hub or ingestion is involved:
Rows with a non-zero prior month are unaffected, so the change is limited to the case that was previously returning an infinity.
📝 Notes
Deliberately out of scope: returning
0.0when there is no prior month conflates "no change" with "nothing to compare against".real(null)would separate them, but that is a behaviour change for existing consumers, so this PR only closes the divide-by-zero hole. Happy to follow up if you would prefer the stricter version.🤖 Generated with Claude Code