Skip to content

fix: preserve zero results from AVERAGEIF - #1733

Open
Tobiadefami wants to merge 2 commits into
developfrom
fix/averageif-zero-average
Open

fix: preserve zero results from AVERAGEIF#1733
Tobiadefami wants to merge 2 commits into
developfrom
fix/averageif-zero-average

Conversation

@Tobiadefami

@Tobiadefami Tobiadefami commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Context

AVERAGEIF returned a #DIV/0! error when matching values produced a valid average of 0.

This happened because the result used a logical OR fallback, which treated 0 as if no average had been
calculated. This change uses nullish coalescing so that only an absent result produces #DIV/0!, while a
valid zero is returned normally.

How did you test your changes?

Added a regression test where the matching values are -1 and 1, producing an average of 0.

The test was verified to fail with #DIV/0! before the fix and pass with 0 after the fix.

I also ran:

  • The focused AVERAGEIF test suite: all 14 tests passed.
  • npm run bundle:cjs: TypeScript and the CommonJS build completed successfully.
  • Targeted linting: no errors.

Types of changes

  • Breaking change (a fix or a feature because of which an existing functionality doesn't work as
    expected anymore)
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues:

None.

Checklist:

  • I have reviewed the guidelines about [Contributing to HyperFormula](https://
    hyperformula.handsontable.com/guide/contributing.html) and I confirm that my code follows the code style of
    this project.
  • I have signed the Contributor License Agreement.
  • My change is compliant with the [OpenDocument](https://docs.oasis-open.org/office/OpenDocument/v1.3/
    os/part4-formula/OpenDocument-v1.3-os-part4-formula.html) standard.
  • My change is compatible with Microsoft Excel.
  • My change is compatible with Google Sheets.
  • I described my changes in the [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/master/
    CHANGELOG.md) file.
  • My changes require a documentation update.
  • My changes require a migration guide.

Note

Low Risk
Single-expression change in AVERAGEIF error handling with no auth, data, or API surface impact.

Overview
AVERAGEIF incorrectly returned #DIV/0! when the matched cells produced a true average of 0 (e.g. values -1 and 1).

The return path in ConditionalAggregationPlugin switched from logical OR (||) to nullish coalescing (??) when falling back to #DIV/0!. A computed 0 is no longer treated as “no result”; only a missing average (no matching count) still yields the division-by-zero error.

The unreleased CHANGELOG entry documents this fix.

Reviewed by Cursor Bugbot for commit 8775411. Bugbot is set up for automated code reviews on this repo. Configure here.

@cla-external-contractor-signup

Copy link
Copy Markdown

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 13, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
hyperformula-docs 8775411 Commit Preview URL

Branch Preview URL
Aug 13 2026, 10:00 AM

@Tobiadefami
Tobiadefami requested review from sequba and removed request for sequba August 13, 2026 09:58
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.31%. Comparing base (61ead73) to head (8775411).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1733   +/-   ##
========================================
  Coverage    97.31%   97.31%           
========================================
  Files          195      195           
  Lines        15719    15719           
  Branches      3455     3455           
========================================
  Hits         15297    15297           
  Misses         414      414           
  Partials         8        8           
Files with missing lines Coverage Δ
...interpreter/plugin/ConditionalAggregationPlugin.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

Performance comparison of head (8775411) vs base (61ead73)

                                     testName |    base |    head | change
--------------------------------------------------------------------------
                                      Sheet A |  364.54 |  369.09 | +1.25%
                                      Sheet B |  114.34 |   112.8 | -1.35%
                                      Sheet T |  101.16 |   99.24 | -1.90%
                                Column ranges |  495.36 |  496.93 | +0.32%
                                Sorted lookup | 15311.6 | 14605.6 | -4.61%
Sheet A:  change value, add/remove row/column |    10.1 |   10.27 | +1.68%
 Sheet B: change value, add/remove row/column |   96.93 |   98.75 | +1.88%
                   Column ranges - add column |  123.12 |  125.53 | +1.96%
                Column ranges - without batch |  406.09 |  389.48 | -4.09%
                        Column ranges - batch |  103.88 |   95.44 | -8.12%

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.

1 participant