Statistical functions
AVERAGEIF
Matches all 16 recorded answers
Recorded: 16 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | AVERAGEIF |
| Bulgarian | AVERAGEIF |
| Czech | AVERAGEIF |
| Danish | MIDDEL.HVIS |
| German | AVERAGEIF |
| Greek | AVERAGEIF |
| English (Australia) | AVERAGEIF |
| English (United Kingdom) | AVERAGEIF |
| English (United States) | AVERAGEIF |
| Spanish | PROMEDIO.SI |
| Estonian | AVERAGEIF |
| Finnish | KESKIARVO.JOS |
| French | MOYENNE.SI |
| Hebrew | AVERAGEIF |
| Croatian | AVERAGEIF |
| Hungarian | ÁTLAGHA |
| Indonesian | AVERAGEIF |
| Italian | AVERAGEIF |
| Japanese | AVERAGEIF |
| Korean | AVERAGEIF |
| Lithuanian | AVERAGEIF |
| Latvian | AVERAGEIF |
| Norwegian | GJENNOMSNITTHVIS |
| Dutch | AVERAGEIF |
| Polish | ŚREDNIA.JEŻELI |
| Portuguese (Brazil) | MÉDIAIF |
| Portuguese (Portugal) | MÉDIA.SE |
| Romanian | AVERAGEIF |
| Russian | СРЗНАЧЕСЛИ |
| Slovak | AVERAGEIF |
| Slovenian | AVERAGEIF |
| Serbian (Latin) | AVERAGEIF |
| Swedish | MEDEL.OM |
| Thai | AVERAGEIF |
| Turkish | EĞERORTALAMA işlevi |
| Ukrainian | AVERAGEIF |
| Vietnamese | AVERAGEIF |
| Chinese (Simplified) | AVERAGEIF |
| Chinese (Hong Kong) | AVERAGEIF |
| Chinese (Traditional) | AVERAGEIF |
Names from Microsoft's support site.
What it does
AVERAGEIF(range, criteria, [average_range])
AVERAGEIF(range, criteria, [average_range]) builds a selection mask over range by testing
each cell against criteria, and returns the arithmetic mean of the numeric cells of
average_range at the selected positions:
M = { i : criteria(range[i]) }
result = ( Σ_{i ∈ M, average_range[i] numeric} average_range[i] )
/ #{ i ∈ M : average_range[i] numeric }
Two counts are in play and they are not the same. The mask counts matching positions; the
divisor counts matching positions holding a number. A matched cell that is empty, text, or
logical contributes to neither numerator nor divisor. That is why AVERAGEIF can return
#DIV/0! on a range where the criterion matched plenty of cells.
The function decomposes cleanly into three independent stages, and every difficult question about it belongs to exactly one of them:
- Criteria parsing — turning the
criteriaargument into a comparison operator plus an operand. - Cell matching — applying that comparison to each cell of
range. - Filtered reduction — averaging the selected cells of
average_range.
Arguments
| Argument | Meaning | Default |
|---|---|---|
range | The cells the criterion is tested against. Required. | — |
criteria | The test. A number, expression, cell reference, or text. Required. | — |
average_range | The cells actually averaged. Optional. | range |
Microsoft describes range as "One or more cells to average, including numbers or names,
arrays, or references that contain numbers", criteria as "The criteria in the form of a
number, expression, cell reference, or text that defines which cells are averaged", and
average_range as "The actual set of cells to average. If omitted, range is used."
Try it
Quirks
The criteria mechanism
| Criterion form | Parsed as |
|---|---|
5 or a cell holding 5 | equality against the number 5 |
TRUE | equality against the logical TRUE |
">5" | greater-than against the number 5 |
"<>abc" | not-equal against the text abc |
"<=", "<", ">", ">=", "<>", "=" prefixes | the corresponding comparison |
"apple" (no prefix) | equality against text |
"=" with nothing after it | equality against blank |
"a*", "a?c" | text equality with wildcards |
Matching is kind-aware. A numeric criterion matches numeric cells, and also text cells whose
content parses as that number; it does not match logicals. A text criterion matches only text
cells. A logical criterion matches logical cells, and text that reads as a logical. This means
AVERAGEIF(A:A, 1) and AVERAGEIF(A:A, TRUE) select different cells even though TRUE
coerces to 1 in arithmetic.
The average_range anchoring rule
Microsoft states it directly: "The average_range does not need matching dimensions as range; calculations begin from the top-left cell and correspond to range dimensions."
So AVERAGEIF(A1:A10, ">5", B1) averages B1:B10, not the single cell B1. The third
argument behaves as an anchor, not as a range: only its top-left corner is load-bearing, and
the shape is taken from range.
This is a genuine trap, and it is the reason AVERAGEIFS — which requires exact shape
agreement — is not simply "AVERAGEIF with more criteria". Moving a formula from one to the
other can change which cells are averaged without changing any argument text.
Result and edge cases
Returns Number.
- No matching cells →
#DIV/0!, documented by Microsoft: "If no cells in the range meet the criteria, AVERAGEIF returns the #DIV/0! error value." - Empty cells in
average_rangeare ignored; Microsoft states this. rangeandaverage_rangeoverlapping or identical is ordinary and is the default.- Arrays. The surface lifts natively (
lift_broadcast_profile: surface_native).
Documentation divergences
The Handbook exists partly to publish these. Three are visible on this surface without running Excel at all.
- The
#DIV0!spelling. Microsoft's remark text renders the error as#DIV0!on both theAVERAGEIFandAVERAGEIFSpages, while the same pages use#DIV/0!elsewhere. This is a typographical defect in the documentation rather than a behavioural claim, but it is worth recording so that a reader searching for the error code finds the remark.
How to implement
Numerical notes
The reduction is a plain sequential f64 accumulation followed by one division, so the error
analysis is exactly AVERAGE's: a bound proportional to
(\sum|x_i|), a condition number of (\sum|x_i|/|\sum x_i|), and sensitivity to summation
order. Nothing about the criteria stage improves it.
What the criteria stage adds is a second numerical question that has nothing to do with
summation: the tolerant comparison. Because compare_excel_numbers works on a
15-significant-digit truncation rather than the full 53-bit significand, the selection mask
itself is a function of a rounding decision. Two numbers that differ in the sixteenth digit
select together. For a conditional average this is a bigger effect than any summation error:
a mis-selected cell changes the answer at full magnitude, while a summation error changes it in
the last bits. Anyone auditing an AVERAGEIF should look at the mask before looking at the
arithmetic.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
AVERAGEIF · 1 lines · calc-func/src/catalogue/conditional.rs on GitHubconditional(AVERAGEIF, "AVERAGEIF", (2, 3), AVERAGE_RANGE, averageif)
averageif · 11 lines · calc-func/src/catalogue/conditional.rs on GitHub/// AVERAGEIF: the matched numbers added from 0 and divided by how many there are; #DIV/0! when
/// there is none.
fn averageif(
arguments: &[CalcValue],
services: &mut EvalServices<'_>,
) -> Result<CalcValue, FunctionFault> {
let site = Site::new(AVERAGEIF, services);
Site::finish(
single(&site, arguments, services, true).and_then(|plan| mean(&site, &plan, services)),
)
}
Kernels shared with other functions
readercatalogue/aggregateread_referencecatalogue/aggregatenumberscatalogue/comparisonin_bandcatalogue/comparisonRounded::upcatalogue/comparisonRoundings::ofcatalogue/comparisonRoundings::disjointcatalogue/comparisontextscatalogue/comparisoncomparecatalogue/comparison/collationweighedcatalogue/comparison/collationmeasured_iteration_extensioncatalogue/comparison/collationtablecatalogue/comparison/sort_keydecode64catalogue/comparison/sort_keyReader::bytecatalogue/comparison/sort_keyReader::varintcatalogue/comparison/sort_keyReader::donecatalogue/comparison/sort_keyin_rangescatalogue/comparison/sort_keybuildcatalogue/comparison/sort_keyhan_basecatalogue/comparison/sort_keyderivecatalogue/comparison/sort_keyshared_jamo_tailscatalogue/comparison/sort_keyordinary_jamo_prefixcatalogue/comparison/sort_keyindependent_jamo_suffixcatalogue/comparison/sort_keyjamo_leading_primarycatalogue/comparison/sort_keyleading_ordercatalogue/comparison/sort_keyBefore::separate_specialcatalogue/comparison/sort_keyGathered::kanacatalogue/comparison/sort_keyGathered::unitcatalogue/comparison/sort_keypartscatalogue/comparison/sort_keydiacritic_ordercatalogue/comparison/sort_keydiacriticscatalogue/comparison/sort_keyconditionalcatalogue/conditionaltotalcatalogue/conditionalmeancatalogue/conditionalRange::shapecatalogue/conditionalrangecatalogue/conditionalsinglecatalogue/conditionalPlan::each_matchedcatalogue/conditionalrowcatalogue/conditionaloffsetcatalogue/conditionalread_rangecatalogue/conditionalverdictscatalogue/conditionaltarget_cellscatalogue/conditionalusedcatalogue/conditionalMatch::ofcatalogue/conditionalMatch::negatedcatalogue/conditionalOp::holdscatalogue/conditionalOp::is_equalitycatalogue/conditionalspellscatalogue/conditionalcriterioncatalogue/conditionalrankcatalogue/conditionalcriterion_textcatalogue/conditionaldecidedcatalogue/conditionalCriterion::verdictcatalogue/conditionalequalitycatalogue/conditionalis_surrogatecatalogue/conditionalwildcardcatalogue/conditionallow32decimalNatural::from_u64decimalNatural::pow10decimalNatural::normalizedecimalNatural::is_zerodecimalNatural::mul_add_smalldecimalNatural::times_pow10decimalNatural::times_pow5decimalNatural::times_pow2decimalExactDecimal::binarydecimaltextported/text_kernelstext_from_strported/text_kernelsfold_unitported/text_kernelspush_singleton_or_originalported/text_kernelspush_lowerported/text_kernelslowerported/text_kernels
Argument and result plumbing
operandcoerce
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Alternatives
Relationships
- AVERAGEIFS — the plural form. Not a superset: it requires exact shape agreement, so it cannot express the anchoring shorthand, and its documentation states the opposite logical rule. Argument order is also reversed — the averaged range comes first.
COUNTIF/SUMIF— the same criteria mechanism with a different reduction.AVERAGEIFis mathematicallySUMIF/COUNTIFonly when every matched cell is numeric; otherwise the divisors differ, becauseCOUNTIFcounts matched cells whileAVERAGEIFcounts matched numeric cells.MAXIFS/MINIFS— same module, same criteria mechanism, different reduction; note they return0rather than an error when nothing matches, whichAVERAGEIFdoes not.DAVERAGE— the database-family conditional mean, with a criteria range rather than a criteria expression; see DAVERAGE for that mechanism.FILTER+AVERAGE— the modern dynamic-array route, which uses ordinary worksheet comparison rather than the criteria language and therefore does not inherit the wildcard or the tolerant-numeric rules.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents