Skip to content

SUBTOTAL 109-111 leave out nested subtotals like 1-11 (#556) - #607

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-556
Oct 13, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-556

Conversation

@MarekSpodBiedry

Copy link
Copy Markdown
Contributor

Fixes #556.

SUBTOTAL(101..111, ...) counted a nested SUBTOTAL/AGGREGATE cell in its range as data, so SUBTOTAL(109,A1:A2) with A1=2 and A2==SUBTOTAL(9,A1) gave 4 instead of 2. The cause is in crates/calc/src/eval.rs: SUBTOTAL 101-111 are mapped to AGGREGATE option 5, and skip_nested was options <= 3, so for 101-111 it was false.

Microsoft's SUBTOTAL reference says nested subtotals in the references are always ignored, whatever the function number. The fix makes skip_nested true for every SUBTOTAL call. AGGREGATE keeps its own rule (it leaves out nested cells only for options 0-3), so its behaviour does not change.

Test subtotal_109_skips_nested_subtotal in crates/calc/src/tests.rs:

  • the issue's repro: SUBTOTAL(109,A1:A2), SUBTOTAL(9,A1:A2) and SUBTOTAL(109,A1) all give 2 (the first gave 4 before the fix);
  • the issue's three-row control with row 2 hidden by hand: SUBTOTAL(109,A1:A3) gives 1 (the hidden row and the nested subtotal are both left out) and SUBTOTAL(9,A1:A3) gives 3.

The existing subtotal_skips_hidden and subtotal_skips_filtered_rows tests cover the hidden-row and filter rules, which do not change.

@MarekSpodBiedry
MarekSpodBiedry marked this pull request as ready for review October 12, 2026 06:53
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 28c5bf1 into storytold:main Oct 13, 2026
1 check failed
@echelon

echelon commented Oct 13, 2026

Copy link
Copy Markdown
Member

Merged — thank you @MarekSpodBiedry for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(calc): SUBTOTAL 109 counts a nested subtotal in the result

3 participants