Repository navigation
Functions: MODE/VALUE/SUMPRODUCT text args, ADDRESS [Book]Sheet, Excel-style lookup bisection, SUBTOTAL skips filtered rows - #419
Merged
Conversation
…ook]Sheet, Excel-style lookup bisection, SUBTOTAL skips filtered rows (table filter criteria kept) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 11, 2026
Merged
Member
|
Merged — thank you for the contribution! If you haven't already, please join our Discord: https://discord.gg/artcraft |
This was referenced Nov 13, 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
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.
What changed
Function fixes found by comparing GridCraft against Excel-cached formula results in test workbooks. One PR because they came out of the same comparison run; the parts are independent and grouped below.
MODE / MODE.SNGL / MODE.MULT (
crates/functions/src/stat.rs)mode_numbers: inside multi-cell ranges and arrays only numbers count (as before), but direct text (even numeric text like"1") and a single-cell reference to text or a blank cell give#VALUE!. Arguments are read left to right, so the first error wins (MODE(1,1,#DIV/0!,"1")is#DIV/0!,MODE("1",1,#DIV/0!)is#VALUE!).VALUE (
crates/functions/src/text.rs)VALUE("")and whitespace-only text are now#VALUE!(they returned 0). A blank cell still reads as 0.SUMPRODUCT (
crates/functions/src/math.rs)#VALUE!. Text inside arrays and multi-cell ranges still counts as 0.ADDRESS (
crates/functions/src/lookup.rs)[Book]Sheetsheet_text is judged by its parts, soADDRESS(2,3,3,TRUE,"[Book1]Sheet1")gives[Book1]Sheet1!$C2instead of'[Book1]Sheet1'!$C2. Names with spaces are still quoted ('[My Book]Sheet1'!$A$1,'EXCEL SHEET'!R2C3).Approximate match: VLOOKUP / HLOOKUP / LOOKUP / MATCH (
crates/functions/src/lookup.rs)bsearch_lastnow bisects the whole vector the way Excel does, instead of first filtering to entries of the needle's type and searching those. A probe of a different type moves to the nearest same-type entry below it in the window (or the window moves up past it). An equal probe ends the search, then the run of equal entries after it is taken, so sorted duplicates give the last one. On unsorted, mixed-type data the answer now matches Excel's (e.g.VLOOKUP(534, {"INTEGRAL";0;1;2;534;9999999999;-9999999999}, …)finds 534). No allocation; linear work in the worst case, including long runs of trailing blanks.XLOOKUP / XMATCH binary search, search_mode ±2 (
crates/functions/src/lookup.rs)binary_order,bsearch_firstandbsearch_uptousepartition_point. Observed case:XLOOKUP(46523, {9700;"xyz";"xyz";160726;204100;510300}, rates, 0, 1, 2)returns the row of the first"xyz"(0.22).SUBTOTAL leaves out filtered rows (
crates/calc,crates/model,crates/xlsx,crates/engine)SUBTOTALwith function numbers 1–11 now leaves out rows hidden by a filter (rows hidden by hand still count). 101–111 behave as before (all hidden rows left out). AGGREGATE is unchanged.Sheet::is_row_filtered: a hidden row is "filtered" when it is inside the sheet AutoFilter while that has criteria, or inside the data range of a table whose AutoFilter has criteria.Tablegetsfilter: Vec<(u32, FilterCriterion)>(#[serde(default)]). XLSX reads and writes the table<autoFilter>criteria through the existingread_autofilter/autofilter_xml. Before this they were dropped on load, leaving only the filter button. Tables created by Insert ▸ Table and the Forecast Sheet start with no criteria.FilterCriterion::Icon { set, id }for<iconFilter>, read and written on table and sheet AutoFilters.apply_filterdoes not evaluate icons: rows keep their current visibility.table.headeroff and toggling a table's filter button off now clear the table's criteria.Tests
functions::stat::tests::mode_scalar_arguments: 8 cases × MODE and MODE.SNGL, plus MODE.MULT.functions::text::tests::value_observed: 5 cases.functions::math::tests::sumproduct_scalar_arguments: 7 cases.functions::lookup::tests::shape_and_address: 4 new ADDRESS cases.functions::lookup::tests::approximate_match_follows_bisection: VLOOKUP/HLOOKUP/LOOKUP on the mixed-type test data, sorted duplicates, descending MATCH -1, text-only data, 10,000 trailing blanks.functions::lookup::tests::xlookup_binary_search_observed: 5 XLOOKUP cases with search_mode 2 / -2.calc::tests::subtotal_skips_filtered_rows: filtered table, filtered sheet AutoFilter, a row hidden by hand outside both, SUBTOTAL 9/109/2 and AGGREGATE.xlsx::tests::roundtrip::full_roundtrip: the sample table now has a values criterion and an icon criterion, and they must survive save and reload.Expected values are Excel results cached in the test workbooks, or come from Microsoft's documentation examples (ADDRESS) where the test says so.
Commands run:
All pass.
The mismatches were found with the
gridcraft-cli checkoracle subcommand (#416, separate PR). This PR does not need that code.Docs
docs/function-parity.md: headerChange:line and a history row. No function counts change.docs/file-format-parity.md: headerChange:line and a history row for table AutoFilter criteria and icon filters.The header lines and top history rows of both docs will conflict with sibling PRs that touch them (#418, #421, #417 for function-parity.md; #423, #422, #417 for file-format-parity.md), so a rebase will be needed. Any PR that adds a
Table { … }literal also needsfilter: vec![]once this lands (for example the table test in #423).Not done
is_row_filteredtreats every hidden row inside a filtered range as filtered. A row hidden by hand inside an active filter range counts as filtered.Unverified: needs confirmation in Excel
[My Book]Sheet1case (quoted) follows the sheet-name quoting rule. No Excel result was observed for it.