You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Data Subtotal: the grand total ends at the last data row, as in Excel - #4414
subtotal in crates/engine/src/cmd/data/grouping.rs wrote the grand total's SUBTOTAL down to the row above it, which is the last group's own total: =SUBTOTAL(9,B2:B6). Excel writes =SUBTOTAL(9,B2:B5), ending at the last group's last data row.
SUBTOTAL skips nested SUBTOTALs, so the two agree until the last group's total is replaced by a value. Then GridCraft's grand total counted it (160) and Excel's didn't (60).
What changed
The grand total's range ends at last - 2, the last data row, instead of last - 1. Group totals, labels, bold and the outline are unchanged. The Subtotal dialog (ui-egui/src/dialogs.rs) runs the same command.
QA report
Main vs branch, end to end (gridcraft-cli run --script)
This is the issue's JSONL, extended with its two other replacements (=50+50 over B6, then 100 over B4) and a cell.get of B7 after each step. main is a CLI built from origin/main (d60709a1) and the branch is this PR (7f277ad6). cmp confirmed the two binaries differ.
Step
main B7
this PR B7
Excel (issue)
after Subtotal
=SUBTOTAL(9,B2:B6) → 60
=SUBTOTAL(9,B2:B5) → 60
=SUBTOTAL(9,B2:B5) → 60
B6 (B's total) = 100
160
60
60
B6 = =50+50
160
60
60
then B4 (A's total) = 100
260
160
160 from the start, in both apps
The saved actual.xlsx has <f>SUBTOTAL(9,B2:B6)</f> in B7 from main and <f>SUBTOTAL(9,B2:B5)</f> from this PR.
Test
cmd::data::tests::subtotal_grand_total_ends_at_the_last_data_row runs the issue's range with Sum, Count and Max. For each it checks:
the formulas in B4, B6 and B7 (B2:B3, B5, B2:B5) and the grand total;
the grand total after each of the three replacements: Sum 60, 60, 60, 160; Count 3, 3, 3, 4; Max 30, 30, 30, 100.
The existing subtotal tests still pass, including the grand total over every data row.
Negative control
With the grand total's range back to last - 1 (on top of 7f277ad6, then restored with git checkout), the test fails at its first function: sum, left "=SUBTOTAL(9,B2:B6)", right "=SUBTOTAL(9,B2:B5)".
Excel itself: the Excel column is the issue's report. I didn't have Excel to run it again.
cargo xtask ci: I didn't run the full cargo xtask ci (wasm, layers, the other crates).
Summary by CodeRabbit
Bug Fixes
Corrected grand-total subtotal calculations so they exclude the final group’s subtotal row and use the intended data range.
Grand totals now remain accurate when the final group’s subtotal is replaced with a value or formula, while changes to earlier group subtotals are still reflected.
The grand total's SUBTOTAL ran to the row above it, the last group's total,
as =SUBTOTAL(9,B2:B6). Excel writes =SUBTOTAL(9,B2:B5), ending at the last
group's last data row. A value typed over the last group's total then reached
GridCraft's grand total (160) and not Excel's (60), while one typed over any
other group's total reaches both.
Fixesstorytold#4268
No actionable comments were generated in the recent review.
Walkthrough
The subtotal calculation now excludes the final group subtotal from the grand-total range. A regression test covers sum, count, and max, and checks how replacing group subtotals affects the grand total.
Changes: Subtotal Grand-Total Range
Layer / File(s)
Summary
Grand-total range and regression coverage crates/engine/src/cmd/data/grouping.rs, crates/engine/src/cmd/data/tests.rs
The grand-total formula range now ends at last - 2. A regression test checks the formula range and verifies that replacing the final group subtotal does not change the grand total, while replacing an earlier subtotal does. The test covers sum, count, and max.
The grand-total formula now ends at the last data row, so replacing the final group subtotal with a value no longer changes the grand total. The change is small and covered by a regression test. No remaining merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title states the main behavior change: the grand-total SUBTOTAL range now ends at the last data row, matching Excel. The raw summary and PR objectives both confirm that the grouping.rs range chang…
Linked Issues check
Issue #4268 requires that the grand-total SUBTOTAL generated by Data Subtotal not include the final group's total row. The reviewed head (7f277ad) changes the grand-total range in subtotal (crates/…
Out of Scope Changes check
The PR changes two areas. In grouping.rs, the change is limited to the grand-total range and its explanatory comment, which implements #4268 directly. The test file adds one regression test for the sa…
Full details: Title check
Explanation
The title states the main behavior change: the grand-total SUBTOTAL range now ends at the last data row, matching Excel. The raw summary and PR objectives both confirm that the grouping.rs range change (last - 2 instead of last - 1) is the primary change, and the regression test covers the same behavior. The title is specific, has no file list or vague wording, and is a single sentence. It is slightly long at 69 characters, but it is still clear and readable.
Full details: Linked Issues check
Explanation
Issue #4268 requires that the grand-total SUBTOTAL generated by Data Subtotal not include the final group's total row. The reviewed head (7f277ad) changes the grand-total range in subtotal (crates/engine/src/cmd/data/grouping.rs) from last - 1 to last - 2. The row layout gives last as the grand-total row and last - 1 as the final group's total row, so last - 2 is the final group's last data row. For the issue's A1:B4 example this yields =SUBTOTAL(9,B2:B5), which matches the expected formula. Replacing B6 no longer changes B7. The change also keeps group totals, labels, bold and the outline unchanged. The added test cmd::data::tests::subtotal_grand_total_ends_at_the_last_data_row covers Sum, Count and Max, the formulas in B4, B6 and B7, and the grand total after each replacement step. The PR reports that the test fails when the range returns to last - 1. I did not read the test file or run the tests. The result relies on the reported test results and the code reading of the range arithmetic. The issue's Excel comparison and #3790 (running Subtotal again) are not coding requirements of this PR.
Full details: Out of Scope Changes check
Explanation
The PR changes two areas. In grouping.rs, the change is limited to the grand-total range and its explanatory comment, which implements #4268 directly. The test file adds one regression test for the same behavior. The PR does not change the group total logic, labels, bold, outline, or the Subtotal dialog path, which uses the same command. The PR description states that existing workbook formulas and #3790 are not covered. These exclusions are not changes in this PR. I found no unrelated changes in the evidence available.
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.
Reviewing files that changed from the base of the PR and between d60709a and 7f277ad.
Files selected for processing: 2
crates/engine/src/cmd/data/grouping.rs
crates/engine/src/cmd/data/tests.rs
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
emrahoksak
pushed a commit
to emrahoksak/girdcraft-
that referenced
this pull request
Nov 18, 2026
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
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 #4268
What was wrong
subtotalincrates/engine/src/cmd/data/grouping.rswrote the grand total'sSUBTOTALdown to the row above it, which is the last group's own total:=SUBTOTAL(9,B2:B6). Excel writes=SUBTOTAL(9,B2:B5), ending at the last group's last data row.SUBTOTALskips nestedSUBTOTALs, so the two agree until the last group's total is replaced by a value. Then GridCraft's grand total counted it (160) and Excel's didn't (60).What changed
The grand total's range ends at
last - 2, the last data row, instead oflast - 1. Group totals, labels, bold and the outline are unchanged. The Subtotal dialog (ui-egui/src/dialogs.rs) runs the same command.QA report
Main vs branch, end to end (
gridcraft-cli run --script)This is the issue's JSONL, extended with its two other replacements (
=50+50over B6, then100over B4) and acell.getof B7 after each step.mainis a CLI built fromorigin/main(d60709a1) and the branch is this PR (7f277ad6).cmpconfirmed the two binaries differ.=SUBTOTAL(9,B2:B6)→ 60=SUBTOTAL(9,B2:B5)→ 60=SUBTOTAL(9,B2:B5)→ 60100=50+50100The saved
actual.xlsxhas<f>SUBTOTAL(9,B2:B6)</f>in B7 frommainand<f>SUBTOTAL(9,B2:B5)</f>from this PR.Test
cmd::data::tests::subtotal_grand_total_ends_at_the_last_data_rowruns the issue's range with Sum, Count and Max. For each it checks:B2:B3,B5,B2:B5) and the grand total;The existing subtotal tests still pass, including the grand total over every data row.
Negative control
With the grand total's range back to
last - 1(on top of7f277ad6, then restored withgit checkout), the test fails at its first function:sum, left"=SUBTOTAL(9,B2:B6)", right"=SUBTOTAL(9,B2:B5)".Gate (macOS arm64, at
7f277ad6)cargo fmt --all -- --checkcargo clippy -p gridcraft-engine --all-targets -- -D warningscargo test -p gridcraft-engineNot covered
cargo xtask ci: I didn't run the fullcargo xtask ci(wasm, layers, the other crates).Summary by CodeRabbit