Skip to content

MATCH/VLOOKUP/HLOOKUP with a scalar number and AGGREGATE 1-13 with values follow Excel - #2796

Open
Harrison-Booth wants to merge 2 commits into
storytold:mainfrom
Harrison-Booth:gc-fn-edge-cases-lookup
Open

Harrison-Booth wants to merge 2 commits into
storytold:mainfrom
Harrison-Booth:gc-fn-edge-cases-lookup

Conversation

@Harrison-Booth

@Harrison-Booth Harrison-Booth commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Two Excel behaviours GridCraft missed when a function gets a value where it expects a range.

Measured in Excel 16 (COM, new temporary workbook with A20=1, A21=2, closed unsaved):

Formula Excel GridCraft before
MATCH(1,1), MATCH(1,1,0), MATCH(1,SUM(1)) #N/A 1
VLOOKUP(1,1,1), VLOOKUP(1,1,1,FALSE), VLOOKUP(1,SUM(1),1) #N/A 1
HLOOKUP(1,1,1) #N/A 1
MATCH(1,A20), VLOOKUP(1,A20,1), HLOOKUP(1,A20,1), MATCH(1,{1}), VLOOKUP(1,{1},1) 1 1 (unchanged)
AGGREGATE(1,1,1), AGGREGATE(1,6,{1,2}), AGGREGATE(9,6,1), AGGREGATE(9,6,A20*2), AGGREGATE(9,6,A20:A21*2) #VALUE! number
AGGREGATE(9,6,A20), AGGREGATE(9,6,A20:A21) 1, 3 unchanged
AGGREGATE(14,6,{1,2},1), AGGREGATE(14,6,A20:A21*2,1) 2, 4 unchanged

The lookup change applies to a number that is not a reference or array. Excel also gives #VALUE! for MATCH(1,"a"); that is left as it was. LOOKUP, XMATCH and XLOOKUP accept a scalar in Excel (all give 1) and are unchanged. SUBTOTAL is not changed (Excel refuses to enter SUBTOTAL(9,1), so there is nothing to compare).

Tests: crates/functions/src/lookup.rs and crates/calc/src/tests.rs.

Not run: the Rust suite (not built on this machine; cargo fmt --check only), so CI is the check. No UI change, so no other platform applies.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • AGGREGATE functions 1–13 now return #VALUE! when given a scalar or array instead of a cell reference. Cell references remain supported.
    • Lookup and MATCH functions now return #N/A when given a standalone numeric lookup array. Numeric cell references and arrays continue to work.

…ferences

MATCH, VLOOKUP and HLOOKUP return #N/A when the lookup array is a
literal or computed number; AGGREGATE functions 1-13 return #VALUE! for
arrays and values, as Excel does.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 27 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between dbf676f and eed9d2e.

Files selected for processing: 1

  • crates/calc/src/tests.rs

No actionable comments were generated in the recent review.

Walkthrough

AGGREGATE now rejects non-error value arguments for function numbers below 14. MATCH, VLOOKUP, and HLOOKUP now return #N/A for numeric lookup-array arguments that do not originate from references. Tests cover these input rules and accepted reference or array inputs.

Changes: Reference Argument Validation

Layer / File(s) Summary
AGGREGATE input rules
crates/calc/src/eval/reference_fns.rs, crates/calc/src/tests.rs
AGGREGATE function numbers below 14 now reject non-error value arguments. Tests cover scalar and array inputs, cell references, and array inputs to function 14.
Lookup-array validation
crates/functions/src/lookup.rs
MATCH, VLOOKUP, and HLOOKUP now return #N/A for numeric lookup-array arguments that do not originate from references. Tests cover numeric scalar arguments and accepted one-cell references and arrays.

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

Change: Bug fix

Suggested reviewers: echelon, aiongg

Merge Risk: Minimal · previous review dbf67

The changed lookup result matches the documented treatment of computed numbers. No issue identified here needs to be resolved before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies both main changes: Excel-compatible handling for scalar numbers in MATCH/VLOOKUP/HLOOKUP and reference requirements for AGGREGATE functions 1–13.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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 11bb673 and dbf676f.

Files selected for processing: 3

  • crates/calc/src/eval/reference_fns.rs
  • crates/calc/src/tests.rs
  • crates/functions/src/lookup.rs

Limit details: You’ve used all 10 included reviews currently available.

@FredApps FredApps 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.

ReviewerA — source-read COMMENT (not an approval)

I read the hunk and the start of the tests: AGGREGATE with a function number 1 to 13 now returns #VALUE! when its data argument is a literal or computed value rather than a reference (Excel's behaviour), while error values still propagate. The title also promises MATCH/VLOOKUP/HLOOKUP with a scalar number; I did not read that part. Please add tests for AGGREGATE(9,6,5), AGGREGATE(14,6,5,1) (functions 14 to 19 accept arrays and values), and a scalar lookup value.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

@Harrison-Booth

Harrison-Booth commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Added the requested reference-form cases for AGGREGATE 9 and 14, plus a scalar MATCH case. Excel returned #VALUE!, 5, and #N/A respectively; the focused Windows calc test and cargo fmt --check pass.

Commit eed9d2e0

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.

2 participants