fix: preserve zero results from AVERAGEIF - #1733
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 | 2eb85e9 | Commit Preview URL Branch Preview URL |
Sep 02 2026, 10:45 AM |
Performance comparison of head (2eb85e9) vs base (50e7170) |
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
Approving. Verified rather than eyeballed:
- Differential check of the fix: the same formulas that return
0on this head return#DIV/0!on cleandevelop, so||→??does exactly what the description claims and nothing more. A genuine no-match case (=AVERAGEIF(A1:A2,">100")) still correctly returns#DIV/0!, so the fallback is not weakened. - Paired tests (
hyperformula-testsfix/averageif-zero-average, b163c40) run green against this head: 14/14 infunction-averageif.spec.ts. The regression test is non-vacuous — it fails ondevelopwithout this fix. - CHANGELOG entry present and linked, scope limited to the one expression.
Known and deliberately out of scope: AVERAGEIF's mapFunction still drops CellError values from matching rows (unlike AVERAGEIFS, which propagates them). That is the separate item we settled in the thread on #1732 — not a blocker here.
Note that merging still waits for the freeze to lift.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1733 +/- ##
========================================
Coverage 97.32% 97.32%
========================================
Files 195 195
Lines 15739 15739
Branches 3390 3390
========================================
Hits 15318 15318
Misses 421 421
🚀 New features to boost your workflow:
|
Brings in #1733 (AVERAGEIF zero results). No conflict — it touches CHANGELOG.md and src/interpreter/plugin/ConditionalAggregationPlugin.ts, neither of which this branch changes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QYPSYJTXUDSqycT2HtX3zV
Context
AVERAGEIFreturned a#DIV/0!error when matching values produced a valid average of0.This happened because the result used a logical OR fallback, which treated
0as if no average had beencalculated. This change uses nullish coalescing so that only an absent result produces
#DIV/0!, while avalid zero is returned normally.
How did you test your changes?
Added a regression test where the matching values are
-1and1, producing an average of0.The test was verified to fail with
#DIV/0!before the fix and pass with0after the fix.I also ran:
AVERAGEIFtest suite: all 14 tests passed.npm run bundle:cjs: TypeScript and the CommonJS build completed successfully.Types of changes
expected anymore)
Related issues:
None.
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
Low Risk
Single-operator change in AVERAGEIF result handling with no impact on auth, data, or broader aggregation APIs.
Overview
AVERAGEIFnow returns0when the conditional average is legitimately zero, instead of incorrectly surfacing#DIV/0!.The bug came from using logical OR (
||) afteraverageValue(): a computed average of0was treated like a missing result.ConditionalAggregationPluginswitches that fallback to nullish coalescing (??), so onlyundefined(no matching numeric cells / zero count) still maps to#DIV/0!. CHANGELOG documents the fix under Unreleased.Reviewed by Cursor Bugbot for commit 2eb85e9. Bugbot is set up for automated code reviews on this repo. Configure here.