Skip to content

Advanced Filter: evaluate relative formula criteria on the list's sheet (#4179) - #4248

Open
jayzed80 wants to merge 1 commit into
storytold:mainfrom
jayzed80:fix/advanced-filter-relative-criteria-4179
Open

jayzed80 wants to merge 1 commit into
storytold:mainfrom
jayzed80:fix/advanced-filter-relative-criteria-4179

Conversation

@jayzed80

@jayzed80 jayzed80 commented Nov 15, 2026 •

Copy link
Copy Markdown

Fixes #4179

What was wrong

When a computed (formula) criterion sat on a different sheet from the list, an unqualified reference with a relative row (the issue's =B2>24 on Rules) was evaluated against the criteria sheet. Excel evaluates it against the list's sheet, advancing one row per record, so GridCraft selected the wrong records.

Fix

crates/engine/src/cmd/whatif/advanced_filter.rs, when shifting a computed criterion's references for each list row:

  • unqualified references with a relative row follow the list's sheet and advance per record;
  • explicit references to the list's sheet advance per record;
  • all other references stay fixed on their own sheet (or on the criteria sheet when unqualified with an absolute row).

Tests

crates/engine/src/cmd/whatif/tests.rs, advanced_filter_computed_criteria_on_separate_sheet_matches_excel: the issue's two sheets. Without the fix it fails (wrong records). With the fix it passes and returns the records Excel returns.

Checks

  • cargo test -p gridcraft-engine: no new failures. save_keeps_the_destination_access_restrictions fails on my Linux test machine with and without this change (a file-permission check that depends on the machine).
  • cargo clippy -p gridcraft-engine --all-targets -- -D warnings: clean.
  • cargo fmt --check: clean.

Note: #4180 also edits advanced_filter.rs, in a different function. Whichever merges second may need a small rebase.

Summary by CodeRabbit

  • Bug Fixes
    • Advanced Filter results now correctly account for relative and fixed cell references in computed criteria, including criteria on a separate worksheet. References to other worksheets remain unchanged.
    • Computed criteria using qualified and cross-sheet references now produce more consistent results.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Advanced Filter now shifts computed-criterion references based on the referenced sheet. A regression test checks criteria on a separate worksheet with relative, absolute, qualified, and cross-sheet references.

Changes: Computed criteria reference handling

Layer / File(s) Summary
Shift computed-criterion references
crates/engine/src/cmd/whatif/advanced_filter.rs, crates/engine/src/cmd/whatif/tests.rs
Unqualified relative-row references are bound to the list sheet before shifting. References explicitly targeting the list sheet are shifted; references to other sheets and references without relative rows remain unchanged. The regression test checks the results for five formula reference forms.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: aiongg, dylanmtaylor

Merge Risk: Minimal · up to 7c885

Advanced Filter computed criteria on a separate sheet now evaluate relative-row references against the list sheet, matching Excel. The change is narrow, covered by a targeted regression test, and no outstanding merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: Advanced Filter now evaluates relative formula criteria against the list's sheet. The raw summary confirms this: shift_computed_criterion binds unqualified relative re…
Linked Issues check Passed Directly linked issue #4179 requires that an unqualified relative-row reference in a computed Advanced Filter criterion evaluate against the list sheet, advancing per record. The diff adds `shift_comp…
Out of Scope Changes check Passed The whole-PR diff against the merge base touches only crates/engine/src/cmd/whatif/advanced_filter.rs and crates/engine/src/cmd/whatif/tests.rs. The advanced_filter.rs change is the helper plus …
Full details: Title check

Explanation

The title names the main change: Advanced Filter now evaluates relative formula criteria against the list's sheet. The raw summary confirms this: shift_computed_criterion binds unqualified relative references to the list sheet and advances them per record. The title also carries the issue/PR number (#4179), while the objectives cite PR #4248, which is a minor mismatch and does not affect the title's relevance.

Full details: Linked Issues check

Explanation

Directly linked issue #4179 requires that an unqualified relative-row reference in a computed Advanced Filter criterion evaluate against the list sheet, advancing per record. The diff adds shift_computed_criterion in crates/engine/src/cmd/whatif/advanced_filter.rs. It rebinds SheetSel::Current references with a relative row to the list sheet (list_sheet_name) and shifts them by dr. It also shifts explicit references to the list sheet. All other references stay fixed. The Cond::Computed branch now calls this helper instead of shift_relative on every reference. Mapping to the issue table: =B2>24 shifts per record on the list sheet (expected 102). =$B2>24 has a relative row, so it also shifts (expected 102). ='Input Data'!B2>24 is explicit list-sheet, so it shifts (expected 102). =B$2>24 is absolute-row and unqualified, so it stays on Rules!B2 (expected 101, 102, 103). =Rules!B2>24 is explicit criteria-sheet, so it stays fixed (expected 101, 102, 103). The test advanced_filter_computed_criteria_on_separate_sheet_matches_excel in crates/engine/src/cmd/whatif/tests.rs covers all five formulas with the issue's fixture and expected IDs. The CLI reproduction and the undo, redo, and XLSX reopen checks are verification steps, not coding requirements. I did not execute the test suite. This assessment relies on reading the diff.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base touches only crates/engine/src/cmd/whatif/advanced_filter.rs and crates/engine/src/cmd/whatif/tests.rs. The advanced_filter.rs change is the helper plus the one-line call-site change in the computed-criterion branch. The test is a single new test case for the same issue. No unrelated code changes appear in the diff. The PR description notes a possible rebase conflict with #4180 in a different function. This does not create out-of-scope changes in this PR.

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 8bde636 and 7c885a8.

Files selected for processing: 2

  • crates/engine/src/cmd/whatif/advanced_filter.rs
  • crates/engine/src/cmd/whatif/tests.rs

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

emrahoksak pushed a commit to emrahoksak/girdcraft- that referenced this pull request Nov 18, 2026

This branch has not been deployed

No deployments
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.

Advanced Filter uses the wrong sheet for relative formula criteria

1 participant