Add Excel-compatible nested SUBTOTAL handling#1
Draft
tomtomau wants to merge 1 commit into
Draft
Conversation
SUBTOTAL now ignores cells within its reference range that themselves contain a SUBTOTAL formula, preventing double-counting of nested subtotals to match Excel and Google Sheets. A skipSubtotalCells flag is threaded through the shared aggregation helpers so regular SUM/AVERAGE/COUNT behaviour is unchanged, and subtotal results use a dedicated range-cache key to avoid collisions with plain aggregations over the same range.
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.
Summary
Makes
SUBTOTALignore cells within its reference range that themselves contain aSUBTOTALformula, preventing double-counting of nested subtotals — matching Excel and Google Sheets behaviour.Previously
SUBTOTALdispatched to the same aggregation helpers asSUM/AVERAGE/etc. and treated nestedSUBTOTALcells like any other value, so an outer subtotal spanning sub-group subtotals double-counted them.Approach
skipSubtotalCellsflag is threaded through the shared aggregation chain (do*→reduce/reduceAggregate→evaluateRange→getRangeValues), defaulting tofalsesoSUM/AVERAGE/COUNT/etc. are unchanged.getRangeValues()and the single-cell-reference path skip cells where a newisSubtotalCell()helper detects a top-levelSUBTOTALcall in the cell's formula AST (canonical name comparison, so i18n-safe).SUBTOTAL_<fn>) so it never collides with a plain aggregation over the same range.Applies to both the
1–11and101–111code families. Hidden-row handling (the practical difference between those families) remains out of scope, as the engine is headless and has no row-visibility concept.Tests
New spec
test/unit/interpreter/function-subtotal.spec.tscovering: baseline parity with SUM, nested exclusion for sum/average/count, the1xxcode family, SUM-vs-SUBTOTAL cache independence, single-cell references, and recalculation on edit.npx jest function-subtotal→ 8/8 passnpm run lint→ 0 errors;npm run compile→ clean