Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- Added the `AVERAGEIFS` function. [#1732](https://github.com/handsontable/hyperformula/pull/1732)

## [3.4.0] - 2026-08-10

### Added
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/csCZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'PRŮMĚR',
AVERAGEA: 'AVERAGEA',
AVERAGEIF: 'AVERAGEIF',
AVERAGEIFS: 'AVERAGEIFS',
BASE: 'BASE',
BIN2DEC: 'BIN2DEC',
BIN2HEX: 'BIN2HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/daDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'MIDDEL',
AVERAGEA: 'MIDDELV',
AVERAGEIF: 'MIDDEL.HVIS',
AVERAGEIFS: 'MIDDEL.HVISER',
BASE: 'BASIS',
BIN2DEC: 'BIN.TIL.DEC',
BIN2HEX: 'BIN.TIL.HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/deDE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'MITTELWERT',
AVERAGEA: 'MITTELWERTA',
AVERAGEIF: 'MITTELWERTWENN',
AVERAGEIFS: 'MITTELWERTWENNS',
BASE: 'BASIS',
BIN2DEC: 'BININDEZ',
BIN2HEX: 'BININHEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/enGB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'AVERAGE',
AVERAGEA: 'AVERAGEA',
AVERAGEIF: 'AVERAGEIF',
AVERAGEIFS: 'AVERAGEIFS',
BASE: 'BASE',
BIN2DEC: 'BIN2DEC',
BIN2HEX: 'BIN2HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/esES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const dictionary: RawTranslationPackage = {
AVERAGE: 'PROMEDIO',
AVERAGEA: 'PROMEDIOA',
AVERAGEIF: 'PROMEDIO.SI',
AVERAGEIFS: 'PROMEDIO.SI.CONJUNTO',
BASE: 'BASE',
BIN2DEC: 'BIN.A.DEC',
BIN2HEX: 'BIN.A.HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/fiFI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'KESKIARVO',
AVERAGEA: 'KESKIARVOA',
AVERAGEIF: 'KESKIARVO.JOS',
AVERAGEIFS: 'KESKIARVO.JOS.JOUKKO',
BASE: 'PERUS',
BIN2DEC: 'BINDES',
BIN2HEX: 'BINHEKSA',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/frFR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'MOYENNE',
AVERAGEA: 'AVERAGEA',
AVERAGEIF: 'MOYENNE.SI',
AVERAGEIFS: 'MOYENNE.SI.ENS',
BASE: 'BASE',
BIN2DEC: 'BINDEC',
BIN2HEX: 'BINHEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/huHU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'ÁTLAG',
AVERAGEA: 'ÁTLAGA',
AVERAGEIF: 'ÁTLAGHA',
AVERAGEIFS: 'ÁTLAGHATÖBB',
BASE: 'ALAP',
BIN2DEC: 'BIN.DEC',
BIN2HEX: 'BIN.HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/idID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'RATA-RATA',
AVERAGEA: 'RATA-RATAA',
AVERAGEIF: 'RATA-RATA.JIKA',
AVERAGEIFS: 'AVERAGEIFS',
BASE: 'BASIS',
BIN2DEC: 'BIN.DEC',
BIN2HEX: 'BIN.HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/itIT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'MEDIA',
AVERAGEA: 'MEDIA.VALORI',
AVERAGEIF: 'MEDIA.SE',
AVERAGEIFS: 'MEDIA.PIÙ.SE',
BASE: 'BASE',
BIN2DEC: 'BINARIO.DECIMALE',
BIN2HEX: 'BINARIO.HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/nbNO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'GJENNOMSNITT',
AVERAGEA: 'GJENNOMSNITTA',
AVERAGEIF: 'GJENNOMSNITTHVIS',
AVERAGEIFS: 'GJENNOMSNITT.HVIS.SETT',
BASE: 'BASE',
BIN2DEC: 'BINTILDES',
BIN2HEX: 'BINTILHEKS',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/nlNL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'GEMIDDELDE',
AVERAGEA: 'GEMIDDELDEA',
AVERAGEIF: 'GEMIDDELDE.ALS',
AVERAGEIFS: 'GEMIDDELDEN.ALS',
BASE: 'BASIS',
BIN2DEC: 'BIN.N.DEC',
BIN2HEX: 'BIN.N.HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/plPL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'ŚREDNIA',
AVERAGEA: 'ŚREDNIA.A',
AVERAGEIF: 'ŚREDNIA.JEŻELI',
AVERAGEIFS: 'ŚREDNIA.WARUNKÓW',
BASE: 'PODSTAWA',
BIN2DEC: 'DWÓJK.NA.DZIES',
BIN2HEX: 'DWÓJK.NA.SZESN',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/ptPT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'MÉDIA',
AVERAGEA: 'MÉDIAA',
AVERAGEIF: 'MÉDIASE',
AVERAGEIFS: 'MÉDIA.SE.S',
BASE: 'BASE',
BIN2DEC: 'BINADEC',
BIN2HEX: 'BINAHEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/ruRU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'СРЗНАЧ',
AVERAGEA: 'СРЗНАЧА',
AVERAGEIF: 'СРЗНАЧЕСЛИ',
AVERAGEIFS: 'СРЗНАЧЕСЛИМН',
BASE: 'ОСНОВАНИЕ',
BIN2DEC: 'ДВ.В.ДЕС',
BIN2HEX: 'ДВ.В.ШЕСТН',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/svSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'MEDEL',
AVERAGEA: 'AVERAGEA',
AVERAGEIF: 'MEDEL.OM',
AVERAGEIFS: 'MEDEL.OMF',
BASE: 'BASE',
BIN2DEC: 'BIN.TILL.DEC',
BIN2HEX: 'BIN.TILL.HEX',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/languages/trTR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const dictionary: RawTranslationPackage = {
AVERAGE: 'ORTALAMA',
AVERAGEA: 'ORTALAMAA',
AVERAGEIF: 'EĞERORTALAMA',
AVERAGEIFS: 'ÇOKEĞERORTALAMA',
BASE: 'TABAN',
BIN2DEC: 'BIN2DEC',
BIN2HEX: 'BIN2HEX',
Expand Down
7 changes: 7 additions & 0 deletions src/interpreter/functionMetadata/categories/statistical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export const STATISTICAL_DOCS: Record<string, FunctionDoc> = {
documentationUrl: 'https://hyperformula.handsontable.com/docs/guide/built-in-functions.html',
examples: ['=AVERAGEIF(A1:A10, ">5")', '=AVERAGEIF(B1:B10, "apples", C1:C10)'],
},
AVERAGEIFS: {
category: 'Statistical',
shortDescription: 'Returns the arithmetic mean of the cells in a range that meet a set of criteria.',
parameters: [{name: 'average_range', description: 'The range of cells to average.'}, {name: 'criteria_range1', description: 'A range of cells tested against the paired criterion. Further range/criterion pairs can be passed as additional arguments, and only cells meeting every criterion are considered.'}, {name: 'criteria1', description: 'The condition applied to the preceding range, e.g. ">5", "apples", or a cell reference.'}],
documentationUrl: 'https://hyperformula.handsontable.com/docs/guide/built-in-functions.html',
examples: ['=AVERAGEIFS(C1:C10, A1:A10, ">5")', '=AVERAGEIFS(C1:C10, A1:A10, ">5", B1:B10, "apples")'],
},
'BETA.DIST': {
category: 'Statistical',
shortDescription: 'Returns the density of the beta distribution.',
Expand Down
59 changes: 59 additions & 0 deletions src/interpreter/plugin/ConditionalAggregationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ export class ConditionalAggregationPlugin extends FunctionPlugin implements Func
{argumentType: FunctionArgumentType.RANGE, optionalArg: true},
],
},
AVERAGEIFS: {
method: 'averageifs',
parameters: [
{argumentType: FunctionArgumentType.RANGE},
{argumentType: FunctionArgumentType.RANGE},
{argumentType: FunctionArgumentType.NOERROR},
],
repeatLastArgs: 2,
},
SUMIFS: {
method: 'sumifs',
parameters: [
Expand Down Expand Up @@ -207,6 +216,56 @@ export class ConditionalAggregationPlugin extends FunctionPlugin implements Func
return this.runFunction(ast.args, state, this.metadata(functionName), computeFn)
}

/**
* Corresponds to AVERAGEIFS(AverageRange, CriterionRange1, Criterion1, ...)
*
* AverageRange is the range whose matching numeric values are averaged.
* Every CriterionRange and Criterion pair adds a condition that must be satisfied.
*
* @param ast
* @param state
*/
public averageifs(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
const functionName = 'AVERAGEIFS'

const composeFunction = (left: AverageResult | CellError, right: AverageResult | CellError): AverageResult | CellError => {
if (left instanceof CellError) {
return left
} else if (right instanceof CellError) {
return right
} else {
return left.compose(right)
}
}

const computeFn = (values: SimpleRangeValue, ...args: unknown[]) => {
const averageResult = this.computeConditionalAggregationFunction<AverageResult | CellError>(
values,
args as RawInterpreterValue[],
functionName,
AverageResult.empty,
composeFunction,
(arg) => {
if (arg instanceof CellError) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to change here — this is exactly right, and it is actually stricter than its own sibling. averageif's mapFunction a few lines up (around line 206) has no CellError check at all, so an error cell in the averaged range gets silently treated as blank there, while this new averageifs correctly propagates it. Same story as the zero-average fix in #1733 — nice consistency instinct there.

Not asking for a change in this PR — averageif's behavior predates this change and isn't something #1732 broke. But since #1733 is already touching this exact file for the zero-average fix, it might be a cheap one to fold in there too, if you're up for it. Totally optional either way.

Why it matters: a user migrating a single-criterion AVERAGEIF formula to AVERAGEIFS would suddenly start seeing errors that were silently hidden before — confusing, but not something this PR introduced or is responsible for fixing.

return arg
} else if (isExtendedNumber(arg)) {
return AverageResult.single(getRawValue(arg))
} else {
return AverageResult.empty
}
},
)

if (averageResult instanceof CellError) {
return averageResult
} else {
return averageResult.averageValue() ?? new CellError(ErrorType.DIV_BY_ZERO)
}
}

return this.runFunction(ast.args, state, this.metadata(functionName), computeFn)
}

/**
* Corresponds to COUNTIF(Range, Criterion)
*
Expand Down
Loading