Skip to content

[AI] Respect date filters in custom report averages - #9541

Merged
matt-fidd merged 8 commits into
actualbudget:masterfrom
wunsir:fix/9525-custom-report-monthly-average
Nov 22, 2026
Merged

matt-fidd merged 8 commits into
actualbudget:masterfrom
wunsir:fix/9525-custom-report-monthly-average

Conversation

@wunsir

@wunsir wunsir commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

When you apply a toolbar date filter, the average in a custom transaction report now uses the days, weeks, months, quarters, or years the filter covers. The summary, data table, and dashboard table use the same period count. Partial periods and periods with no matching transactions still count once. If the date filter falls entirely outside the report range, the average is 0.00.

I used OpenAI Codex to write the implementation and regression tests.

Related issue(s)

Fixes #9525

Testing

  • On a 34-month synthetic budget, apply Date is between March 15 and July 2, 2026. The total is −500.00 and the average is −100.00 in the summary and data table.
  • On a five-quarter report, filter July through September 2026. The total and quarterly average are both −200.00, including in the saved dashboard table.
  • On a yearly report spanning 2025 and 2026, filter July through September 2026. The total and yearly average are both −200.00. Weekly and daily regressions also verify that a covered week or day with no transactions still counts.
  • The edge cases cover different week starts, partial weeks at the report boundaries, leap day, a Date is between filter crossing a quarter boundary, and filters outside the report range.
  • Ran the browser build, Chromium end-to-end tests, the report and filter test suites, type checking, and the release notes validator.

Checklist

  • Release notes added (see link above)
  • No obvious regressions in affected areas
  • Self-review has been performed - I have read every line of this diff and can explain what each change does and why it is needed

Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 37 15.11 MB → 15.11 MB (-1.34 kB) -0.01%
loot-core 1 5.43 MB → 5.43 MB (+4.23 kB) +0.08%
api 2 4.33 MB → 4.34 MB (+1023 B) +0.02%
cli 1 420.19 kB 0%
crdt 1 11.15 kB 0%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
37 15.11 MB → 15.11 MB (-1.34 kB) -0.01%
Changeset
File Δ Size
src/components/modals/StorageMigrationFailedModal.tsx 🆕 +4.48 kB 0 B → 4.48 kB
src/components/reports/spreadsheets/countFilteredIntervals.ts 🆕 +2.59 kB 0 B → 2.59 kB
src/util/previous-storage.ts 🆕 +673 B 0 B → 673 B
src/components/reports/spreadsheets/custom-spreadsheet.ts 📈 +492 B (+7.24%) 6.64 kB → 7.12 kB
src/budgetfiles/budgetfilesSlice.ts 📈 +259 B (+2.39%) 10.6 kB → 10.86 kB
src/components/Modals.tsx 📈 +247 B (+1.79%) 13.44 kB → 13.68 kB
src/components/reports/graphs/tableGraph/ReportTableRow.tsx 📈 +59 B (+0.74%) 7.82 kB → 7.88 kB
src/components/reports/reports/GetCardData.tsx 📈 +30 B (+0.36%) 8.24 kB → 8.27 kB
src/components/reports/reports/CustomReport.tsx 📈 +90 B (+0.34%) 26.23 kB → 26.32 kB
src/components/reports/ReportSummary.tsx 📈 +8 B (+0.10%) 7.58 kB → 7.59 kB
locale/en.json 📈 +101 B (+0.03%) 292.41 kB → 292.51 kB
src/util/error.ts 📈 +1 B (+0.01%) 7.43 kB → 7.43 kB
locale/sv.json 📉 -886 B (-0.28%) 308.36 kB → 307.49 kB
locale/uk.json 📉 -905 B (-0.37%) 237.6 kB → 236.71 kB
locale/es.json 📉 -753 B (-0.40%) 181.74 kB → 181.01 kB
locale/fr.json 📉 -760 B (-0.43%) 174.48 kB → 173.74 kB
locale/pt-BR.json 📉 -748 B (-0.43%) 169.06 kB → 168.33 kB
locale/de.json 📉 -795 B (-0.43%) 179.68 kB → 178.9 kB
locale/ca.json 📉 -758 B (-0.46%) 161.65 kB → 160.91 kB
locale/pl.json 📉 -701 B (-0.49%) 140.63 kB → 139.94 kB
locale/it.json 📉 -743 B (-0.49%) 147.08 kB → 146.35 kB
locale/zh-Hant.json 📉 -666 B (-0.51%) 127.78 kB → 127.13 kB
locale/ru.json 📉 -1.01 kB (-0.51%) 197.41 kB → 196.39 kB
locale/nl.json 📉 -765 B (-0.52%) 142.79 kB → 142.04 kB
locale/nb-NO.json 📉 -737 B (-0.55%) 130.84 kB → 130.12 kB
src/components/reports/spreadsheets/makeQuery.ts 📉 -24 B (-1.47%) 1.6 kB → 1.57 kB
src/components/settings/StorageBackendToggle.tsx 📉 -292 B (-6.88%) 4.15 kB → 3.86 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 2.94 MB → 2.94 MB (+5.09 kB) +0.17%
static/js/ReportRouter.js 2.01 MB → 2.01 MB (+3.23 kB) +0.16%
static/js/months.js 612.48 kB → 612.73 kB (+260 B) +0.04%
static/js/en.js 292.41 kB → 292.51 kB (+101 B) +0.03%

Smaller

Asset File Size % Changed
static/js/ru.js 197.41 kB → 196.39 kB (-1.01 kB) -0.51%
static/js/uk.js 237.6 kB → 236.71 kB (-905 B) -0.37%
static/js/sv.js 308.36 kB → 307.49 kB (-886 B) -0.28%
static/js/de.js 179.68 kB → 178.9 kB (-795 B) -0.43%
static/js/nl.js 142.79 kB → 142.04 kB (-765 B) -0.52%
static/js/fr.js 174.48 kB → 173.74 kB (-760 B) -0.43%
static/js/ca.js 161.65 kB → 160.91 kB (-758 B) -0.46%
static/js/es.js 181.74 kB → 181.01 kB (-753 B) -0.40%
static/js/pt-BR.js 169.06 kB → 168.33 kB (-748 B) -0.43%
static/js/it.js 147.08 kB → 146.35 kB (-743 B) -0.49%
static/js/nb-NO.js 130.84 kB → 130.12 kB (-737 B) -0.55%
static/js/pl.js 140.63 kB → 139.94 kB (-701 B) -0.49%
static/js/zh-Hant.js 127.78 kB → 127.13 kB (-666 B) -0.51%

Unchanged

Asset File Size % Changed
static/js/AutomaticSyncSettings.js 21.95 kB 0%
static/js/BackgroundImage.js 121.09 kB 0%
static/js/DateSelect.js 2.65 MB 0%
static/js/FormulaEditor.js 771.38 kB 0%
static/js/NotesTagFormatter.js 30.87 kB 0%
static/js/TourHost.js 169.78 kB 0%
static/js/TransactionList.js 87.23 kB 0%
static/js/Value.js 1.76 MB 0%
static/js/bootstrapHyperFormula.js 302 B 0%
static/js/build-shims.js 140 B 0%
static/js/columns.js 686.43 kB 0%
static/js/en-GB.js 13.59 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.46 kB 0%
static/js/narrow.js 316.65 kB 0%
static/js/rolldown-runtime.js 2.03 kB 0%
static/js/theme.js 38.71 kB 0%
static/js/useLocalPref.js 101.16 kB 0%
static/js/web.js 1 kB 0%
static/js/wide.js 304.34 kB 0%
static/js/workbox-window.prod.es5.js 7.21 kB 0%

loot-core

Total

Files count Total bundle size % Changed
1 5.43 MB → 5.43 MB (+4.23 kB) +0.08%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/server/storage/app.ts 📈 +648 B (+35.60%) 1.78 kB → 2.41 kB
home/runner/work/actual/actual/packages/loot-core/src/platform/server/sqlite/storage/absurd-migration.ts 📈 +1.88 kB (+21.90%) 8.59 kB → 10.47 kB
home/runner/work/actual/actual/packages/loot-core/src/platform/server/sqlite/storage/opfs-sahpool.ts 📈 +1.05 kB (+9.34%) 11.3 kB → 12.35 kB
home/runner/work/actual/actual/packages/loot-core/src/platform/server/sqlite/storage/index.ts 📈 +88 B (+8.04%) 1.07 kB → 1.15 kB
home/runner/work/actual/actual/packages/loot-core/src/server/budgetfiles/app.ts 📈 +322 B (+2.41%) 13.05 kB → 13.36 kB
home/runner/work/actual/actual/packages/loot-core/src/platform/server/sqlite/storage/files-store.ts 📈 +49 B (+2.04%) 2.35 kB → 2.4 kB
home/runner/work/actual/actual/packages/loot-core/src/platform/server/sqlite/storage/idb-memory.ts 📈 +203 B (+1.94%) 10.19 kB → 10.39 kB
home/runner/work/actual/actual/packages/loot-core/src/platform/server/sqlite/index.ts 📈 +16 B (+0.40%) 3.88 kB → 3.89 kB
home/runner/work/actual/actual/packages/loot-core/src/shared/errors.ts 📈 +1 B (+0.02%) 5.87 kB → 5.87 kB
View detailed bundle breakdown

Added

Asset File Size % Changed
kcab.worker.D_y2evgX.js 0 B → 5.43 MB (+5.43 MB) -

Removed

Asset File Size % Changed
kcab.worker.C8Vjc7BD.js 5.43 MB → 0 B (-5.43 MB) -100%

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged
No assets were unchanged


api

Total

Files count Total bundle size % Changed
2 4.33 MB → 4.34 MB (+1023 B) +0.02%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/server/storage/app.ts 📈 +634 B (+35.84%) 1.73 kB → 2.35 kB
home/runner/work/actual/actual/packages/loot-core/src/platform/server/sqlite/index.electron.ts 📈 +86 B (+3.51%) 2.39 kB → 2.48 kB
home/runner/work/actual/actual/packages/loot-core/src/server/budgetfiles/app.ts 📈 +302 B (+2.33%) 12.63 kB → 12.93 kB
home/runner/work/actual/actual/packages/loot-core/src/shared/errors.ts 📈 +1 B (+0.02%) 5.8 kB → 5.8 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
index.js 4.33 MB → 4.34 MB (+1023 B) +0.02%

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
models.js 0 B 0%

cli

Total

Files count Total bundle size % Changed
1 420.19 kB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
cli.js 420.19 kB 0%

crdt

Total

Files count Total bundle size % Changed
1 11.15 kB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
index.js 11.15 kB 0%

Copilot AI balanced review requested due to automatic review settings November 13, 2026 11:48
@actual-github-bot actual-github-bot Bot changed the title [AI] Respect date filters in custom report monthly averages [WIP] [AI] Respect date filters in custom report monthly averages Nov 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hello contributor!

We would love to review your PR! Before we can do that, please make sure:

  • ✅ All CI checks pass
  • ✅ The PR is moved from draft to open (if applicable)
  • ✅ The "[WIP]" prefix is removed from the PR title
  • ✅ The PR description follows the provided template, with all checklist boxes filled in
  • ✅ All CodeRabbit code review comments are resolved (if you disagree with anything - reply to the bot with your reasoning so we can read through it). The bot will eventually approve the PR.
  • ✅ Any AI usage is disclosed (see our AI Usage Policy)

A quick note on volume: please get one PR reviewed and merged before opening several more. A stack of simultaneous, similar PRs from one author is reviewed slowly, and low-effort, untested, or undisclosed-AI PRs may be closed without a detailed review.

We do this to reduce the TOIL the core contributor team has to go through for each PR and to allow for speedy reviews and merges.

For more information, please see our Contributing Guide.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Custom reports now use date-filter-covered periods to calculate averages. Spreadsheet data carries the filtered interval count to report displays. When no periods are covered, the average is zero. Tests cover monthly, quarterly, yearly, weekly, and daily reports, including saved dashboard widgets.

Changes: Filtered Report Averages

Layer / File(s) Summary
Count periods covered by date filters
packages/desktop-client/src/components/reports/spreadsheets/makeQuery.ts, packages/desktop-client/src/components/reports/spreadsheets/countFilteredIntervals.ts, packages/desktop-client/src/components/reports/spreadsheets/countFilteredIntervals.test.ts
A shared date transform maps report intervals for query filtering and grouping. The interval counter evaluates date and other report conditions. Tests cover date boundaries, filter combinations, and report-range limits.
Include filtered counts in spreadsheet data
packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
Spreadsheet generation calculates and includes the filtered interval count for eligible reports in empty and populated results.
Use filtered counts in report averages
packages/desktop-client/src/components/reports/reports/CustomReport.tsx, packages/desktop-client/src/components/reports/reports/GetCardData.tsx, packages/desktop-client/src/components/reports/ReportSummary.tsx, packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx, packages/desktop-client/e2e/reports.test.ts, packages/docs/docs/reports/custom-reports.md, upcoming-release-notes/fix-custom-report-monthly-average.md
Report displays use the filtered count when available and use zero when no intervals are covered. End-to-end tests check averages across report intervals, chart summaries, data tables, and saved dashboard widgets. Documentation and a release note describe date-filter behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: documentation

Suggested reviewers: jfdoming, matt-fidd, kareemhalabi

Merge Risk: Minimal · up to 2314f

Custom report averages now follow the date filter's covered periods, and the average is zero when no periods are covered. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed [#9525] The bug: with a toolbar date filter, the custom report average divided by the full report interval count. At the reviewed head, custom-spreadsheet.ts computes filteredIntervalCount with countF…
Out of Scope Changes check Passed The changes support the average fix for monthly and quarterly custom reports. countFilteredIntervals.ts and its tests implement the count. custom-spreadsheet.ts passes the count through the data path …
Title check Passed The title "[AI] Respect date filters in custom report averages" matches the main change. The changeset makes custom transaction report averages use the number of periods covered by a toolbar date filt…
Description check Passed The description explains the change. It states that a toolbar date filter now sets the average period count in custom transaction reports, and that the summary, data table, and dashboard table use the…
Full details: Linked Issues check

Explanation

[#9525] The bug: with a toolbar date filter, the custom report average divided by the full report interval count. At the reviewed head, custom-spreadsheet.ts computes filteredIntervalCount with countFilteredIntervals for Monthly and Quarterly intervals when a transaction date filter applies (not totalBudgeted). CustomReport.tsx and GetCardData.tsx pass filteredIntervalCount to ChooseGraph and ReportSummary in place of intervals.length. countFilteredIntervals.ts counts each interval in the report range that has at least one day passing the date filters. For the issue example (March 1 to July 31, 2026), this gives 5, so the average equals the filtered total divided by 5. ReportTableRow.tsx and ReportSummary.tsx use the count and return 0 when it is zero, which covers non-overlapping filters. The unit tests (countFilteredIntervals.test.ts) and Chromium e2e tests (e2e/reports.test.ts) cover partial periods, empty periods, boundaries, and the saved dashboard widget. The makeQuery.ts refactor in this incremental change replaces the intervalMap lookup with getReportQueryDateTransform. For the supported intervals (Yearly, Monthly, Quarterly, Weekly, Daily), the mapping gives the same filter and grouping transforms as before. I did not verify the ReportOptions.intervalMap contents, so equivalence for those intervals rests on the diff logic. The issue's note about the report end date extending to the current date is not a requirement of this PR and was not assessed.

Full details: Out of Scope Changes check

Explanation

The changes support the average fix for monthly and quarterly custom reports. countFilteredIntervals.ts and its tests implement the count. custom-spreadsheet.ts passes the count through the data path and moves make-filters earlier only when grouping or date filtering needs it. CustomReport.tsx, GetCardData.tsx, ReportSummary.tsx, and ReportTableRow.tsx use the count. The e2e tests cover the same behavior. The docs and release note describe the behavior. The makeQuery.ts change extracts getReportQueryDateTransform. It is a supporting refactor for the same date-filter path and keeps the same transforms for the supported intervals. Quarterly support extends the same average defect to Quarterly intervals and is closely related. The DataEntity import removal is a supporting cleanup. No unrelated change was found.

Full details: Title check

Explanation

The title "[AI] Respect date filters in custom report averages" matches the main change. The changeset makes custom transaction report averages use the number of periods covered by a toolbar date filter. The "[AI]" prefix marks AI-assisted authorship and does not hide the subject of the change. The title is specific and concise.

Full details: Description check

Explanation

The description explains the change. It states that a toolbar date filter now sets the average period count in custom transaction reports, and that the summary, data table, and dashboard table use the same count. It lists the edge cases (partial periods, empty periods, non-overlapping filters) and the testing performed. It also links issue #9525 and notes AI tool use, as the template requests.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 78f1896 and 2314f53.

Files selected for processing: 7

  • packages/desktop-client/e2e/reports.test.ts
  • packages/desktop-client/src/components/reports/spreadsheets/countFilteredIntervals.test.ts
  • packages/desktop-client/src/components/reports/spreadsheets/countFilteredIntervals.ts
  • packages/desktop-client/src/components/reports/spreadsheets/custom-spreadsheet.ts
  • packages/desktop-client/src/components/reports/spreadsheets/makeQuery.ts
  • packages/docs/docs/reports/custom-reports.md
  • upcoming-release-notes/fix-custom-report-monthly-average.md
Files skipped from review as they are similar to previous changes: 2

  • packages/docs/docs/reports/custom-reports.md
  • upcoming-release-notes/fix-custom-report-monthly-average.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 13, 2026
@wunsir wunsir changed the title [WIP] [AI] Respect date filters in custom report monthly averages [AI] Respect date filters in custom report monthly averages Nov 16, 2026
@netlify

netlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for actualbudget ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2314f53
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget/deploys/6b02e3e9315cc3da22f1a8fb
😎 Deploy Preview https://deploy-preview-9541.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for actualbudget-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2314f53
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget-website/deploys/6b02e3e96de311a8afc1d326
😎 Deploy Preview https://deploy-preview-9541.www.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@matt-fidd matt-fidd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, it works well in my testing

When the filter doesn't cover any months in the report the average goes blank, e.g. year is 2020 on a 2025 to 2026 report leaves the card empty where it used to show 0.00. Could it show 0.00 there instead?

It also only kicks in for monthly reports, a quarterly report with a Jul to Sep filter still divides by all 5 quarters. Is that intentional?

@wunsir wunsir changed the title [AI] Respect date filters in custom report monthly averages [AI] Respect date filters in monthly and quarterly custom report averages Nov 22, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 22, 2026
@wunsir

wunsir commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Thanks for testing this, @matt-fidd. The average shows 0.00 again when the filter falls outside the report range. The first pass only handled monthly reports. Your July–September example now divides by one quarter.

I also added a regression test for a Date is between filter that crosses a quarter boundary. Could you take another look when you get a chance?

@matt-fidd matt-fidd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Yearly, weekly and daily reports still divide by the whole range, e.g. a yearly report over 2025 to 2026 with a Jul to Sep filter divides by 2 years. Would you be up for covering those here too, or would you rather leave them for a follow-up?

Could we drop the second docs paragraph as well? The bit about an empty category selection feels like more detail than anyone needs there.

@wunsir wunsir changed the title [AI] Respect date filters in monthly and quarterly custom report averages [AI] Respect date filters in custom report averages Nov 22, 2026
@wunsir

wunsir commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Thanks, @matt-fidd. I went ahead and covered daily, weekly, and yearly reports in this PR too. The July–September filter in your example now divides by one year, and I dropped the second paragraph from the docs.

Could you take another look when you get a chance?

@matt-fidd matt-fidd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@matt-fidd
matt-fidd added this pull request to the merge queue Nov 22, 2026
Merged via the queue into actualbudget:master with commit d4e0a18 Nov 22, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Custom Report : Average monthly spending does not respect date filters

3 participants