Repository navigation
Feature/averageifs function - #1732
Conversation
|
@Tobiadefami thanks for the pull request. No CLA step needed here — our records show you signed the Contributor License Agreement on 2026-07-31. That signature came from our previous signing form and has been carried over, so there is nothing for you to re-sign. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
hyperformula-docs | 4b0c53f | Commit Preview URL Branch Preview URL |
Nov 12 2026, 10:36 AM |
Performance comparison of head (4b0c53f) vs base (ec10dbf) |
|
Hey @Tobiadefami — one process thing unrelated to the code itself (which looks solid, see the review above): the paired Could you open a PR there for this branch? Same thing seems to have happened for #1733's companion branch ( Nothing else blocking here — just flagging it now so it's not a surprise closer to merge. |
|
@marcin-kordas-hoc Done — AVERAGEIFS is in test repo PR 36, and the zero-average fix is in test repo PR 35. |
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
Approving. The engine code here got a clean verdict on 16 Aug and the head has not moved since, so this is about closing the loop on the two things that were still open.
Paired tests now verified against this head. CI on this PR last ran on 13 Aug, while the feature/averageifs-function test branch received commits through 22 Aug — so the green badge above never executed the current test suite. I checked it directly instead: engine 8f54b3ab0 against tests d0f8a4f, function-averageifs.spec.ts → 29/29 passing. The 22 Aug delta (percents, currencies, dates) is structurally the same as the MAXIFS siblings and passes here.
One caveat on the record: I could not re-trigger the workflow — this token has no actions: write, and test.yml has no workflow_dispatch, so the only paths are the re-run button or a new push. Worth one click before merge so the PR's own badge reflects a run that included those tests. My local run is evidence the tests pass, not a substitute for the official record.
Also unable to resolve my own thread on ConditionalAggregationPlugin.ts from here (same token limitation) — your reply on it is correct and it needs no further action, so please mark it resolved.
Merging still waits for the freeze to lift.
|
Flagging this before merge, since the PR ticks "My change is compatible with Microsoft Excel" and there is a test that currently locks the divergence in. Repro (verified against this branch at
Why Excel returns that. The AVERAGEIFS page linked from HF-140 states:
This is one of the spots where Excel deliberately makes
So boolean handling is not something Suggested fix. In the map function at lines 248-256, handle booleans explicitly before the Test that needs updating alongside it. In the paired tests PR, Our preference is to match Excel here, rather than record the current behaviour in Generated by Claude Code |
|
// averageif, lines 209-213 == averageifs, lines 259-263
if (averageResult instanceof CellError) {
return averageResult
} else {
return averageResult.averageValue() ?? new CellError(ErrorType.DIV_BY_ZERO)
}This isn't a hypothetical maintenance argument — the duplication has already cost a PR. Those two blocks used to disagree: To be clear about the scope of what I'm suggesting: not one function serving both. The mapping lambda should stay per-function — as I noted in the boolean-handling comment above, Excel deliberately treats private computeAverage(
values: SimpleRangeValue,
conditionArgs: RawInterpreterValue[],
functionName: string,
mapFn: (arg: InternalScalarValue) => AverageResult | CellError,
): InterpreterValueBoth public methods then reduce to assembling their own arguments and passing their own DEV_DOCS asks for exactly this:
And this file already demonstrates the pattern: Generated by Claude Code |
sequba
left a comment
There was a problem hiding this comment.
One inline note on the Portuguese translation, with a broader ask: the localized names added here should each be confirmed against the sources DEV_DOCS lists, rather than inferred from the neighbouring entries in the same pack — ptPT.ts turns out not to be internally consistent, so its neighbours aren't a safe reference.
Generated by Claude Code
sequba
left a comment
There was a problem hiding this comment.
Three code-quality notes on the new averageifs method, grouped into one review since they all sit within lines 220-256 and none of them blocks the PR:
- Line 220 — the JSDoc names the arguments
AverageRange/CriterionRange1/Criterion1, while this same PR publishesaverage_range/criteria_range1/criteria1throughgetFunctionDetailsand the generated docs page. - Line 241 —
composeFunctionis hoisted out ofcomputeFnbut the map lambda isn't, so the latter is rebuilt per output cell under vectorization. Neither captures anything; both belong at module level. - Line 248 — the lambda re-implements the
CellError/ExtendedNumberdispatch thatmapToRawScalarValue(line 65) already provides for the four*IF(S)siblings. Note the sequencing caveat there: if the boolean-handling fix lands, extending the helper is probably better than reusing it as-is.
These are separate from, and smaller than, the two points I raised as top-level comments (Excel boolean semantics, and the averageif/averageifs duplication).
Generated by Claude Code
Thanks for flagging. I verified this directly in Excel for the web. With |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bugbot is paused — on-demand spend limit reachedBugbot uses usage-based billing for this team and has hit its on-demand spend limit. A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue. |
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
question: the 2 September PR comment asking for shared scaffolding between averageif and averageifs has no reply. Is the shared finalizeAverageResult meant as the answer? A one-line reply on that comment would close it.
nit: the description lists tests for "Public function metadata" and "The Portuguese translation" and says 28 focused tests passed. Both tests were removed from hyperformula-tests#36 on request, and function-averageifs.spec.ts now has 33 tests.
…-function # Conflicts: # CHANGELOG.md
…-function # Conflicts: # CHANGELOG.md
|
@marcin-kordas-hoc Yes. The shared scaffolding asked for in this comment is |
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
Approving again at bac0f10. Since my approval at 545f0d4, this branch and hyperformula-tests#36 have only merged develop. The changed lines of both pull requests are the same; only the context around the CHANGELOG entry moved. Both points of that review are closed. Your reply names finalizeAverageResult, which both averageif and averageifs now return through, and the description says 33 tests without listing the two removed ones. With Jest at bac0f10 and ab1b684, function-averageifs.spec.ts, function-averageif.spec.ts and custom-functions.spec.ts pass (89 tests), and CI passed with the paired branch checked out after its last push.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1732 +/- ##
========================================
Coverage 97.37% 97.37%
========================================
Files 209 209
Lines 16557 16580 +23
Branches 3683 3689 +6
========================================
+ Hits 16122 16145 +23
- Misses 427 435 +8
+ Partials 8 0 -8
🚀 New features to boost your workflow:
|

Context
HyperFormula supports
AVERAGEIFand other conditional aggregation functions, but it does not supportAVERAGEIFS.This change adds
AVERAGEIFS, allowing values to be averaged when all corresponding criteria are satisfied. It uses the existing conditional aggregation and caching infrastructure and includes function metadata, translations, documentation, and tests.How did you test your changes?
Added tests covering:
All 33 focused tests passed.
Additionally, I ran:
npm run bundle:cjsnpm run docs:generate-function-docsBoth commands completed successfully.
Types of changes
expected anymore)
Related issues:
Tests: handsontable/hyperformula-tests#36
Checklist:
hyperformula.handsontable.com/guide/contributing.html) and I confirm that my code follows the code style of
this project.
os/part4-formula/OpenDocument-v1.3-os-part4-formula.html) standard.
CHANGELOG.md) file.
Note
Medium Risk
Touches core conditional-aggregation evaluation and error handling; behavior must match Excel for edge cases, though it reuses the same pattern as SUMIFS/MAXIFS.
Overview
Adds
AVERAGEIFS, which averages values inaverage_rangeonly where every criteria range/criterion pair is satisfied, aligned with Excel-style multi-criteria behavior like existingSUMIFS/COUNTIFS.Implementation lives in
ConditionalAggregationPlugin: newaverageifshandler withrepeatLastArgs: 2, wired throughcomputeConditionalAggregationFunctionusing shared helpers (composeAverageResults,mapToAverageResult,finalizeAverageResult).AVERAGEIFnow usesfinalizeAverageResultfor consistent#DIV/0!and error propagation.The function is registered in statistical function metadata, listed in
CHANGELOG.md, added to proprietary license capability (UNGROUPED_FUNCTIONS), and localized across all language packs.Reviewed by Cursor Bugbot for commit f054796. Bugbot is set up for automated code reviews on this repo. Configure here.