Statistical functions
COUNTIF
Matches all 103 recorded answers
Recorded: 103 workbook cells. How we measure this · See the Rust code
Local names in 40 languages
| Language | Name in Excel |
|---|---|
| Arabic | COUNTIF |
| Bulgarian | COUNTIF |
| Czech | COUNTIF |
| Danish | TÆL.HVIS |
| German | ZÄHLENWENN |
| Greek | COUNTIF |
| English (Australia) | COUNTIF |
| English (United Kingdom) | COUNTIF |
| English (United States) | COUNTIF |
| Spanish | CONTAR.SI |
| Estonian | COUNTIF. |
| Finnish | LASKE.JOS |
| French | NB.SI |
| Hebrew | COUNTIF |
| Croatian | COUNTIF |
| Hungarian | DARABHA |
| Indonesian | COUNTIF |
| Italian | CONTA.SE |
| Japanese | COUNTIF |
| Korean | COUNTIF |
| Lithuanian | COUNTIF |
| Latvian | COUNTIF |
| Norwegian | ANTALL.HVIS |
| Dutch | AANTAL.ALS |
| Polish | LICZ.JEŻELI |
| Portuguese (Brazil) | CONT.SE |
| Portuguese (Portugal) | CONTAR.SE |
| Romanian | COUNTIF |
| Russian | СЧЁТЕСЛИ |
| Slovak | COUNTIF |
| Slovenian | COUNTIF |
| Serbian (Latin) | COUNTIF |
| Swedish | ANTAL.OM |
| Thai | COUNTIF |
| Turkish | EĞERSAY |
| Ukrainian | COUNTIF |
| Vietnamese | COUNTIF |
| Chinese (Simplified) | COUNTIF |
| Chinese (Hong Kong) | COUNTIF |
| Chinese (Traditional) | COUNTIF |
Names from Microsoft's support site.
What it does
COUNTIF(range, criteria)
COUNTIF(range, criteria) counts cells satisfying one condition. The criterion can be a number, text, a cell containing the condition, or a comparison such as ">=10".
Try it
Put 4,11,7,13 in B2:B5:
| Formula | Count | Why |
|---|---|---|
=COUNTIF(B2:B5,">=10") | 2 | Eleven and thirteen qualify |
=COUNTIF(B2:B5,">"&B4) | 2 | B4 supplies seven, so the criterion becomes ">7" |
=COUNTIF(B2:B5,">=7")-COUNTIF(B2:B5,">11") | 2 | Include seven through eleven and remove larger values |
For text, put sku-1, SKU-2, sku-*, other in D2:D5. =COUNTIF(D2:D5,"sku-?") counts three: case is ignored and the question mark accepts any one final character. =COUNTIF(D2:D5,"sku-~*") counts one, matching the literal asterisk.
Quirks
Text matching is case-insensitive. * matches a sequence and ? one character; prefix either with ~ to match it literally. Operators belong inside quoted criteria. To use an operator with a cell’s value, concatenate them with &; placing the cell address inside the quoted text does not dereference it.
A numeric equality test and a numeric ordering test are different predicates. The current matcher can convert numeric-looking text for equality, while ordering criteria compare numeric cells. Preserve cell kinds through matching instead of coercing the whole range to numbers first.
Microsoft documents misleading results when matching strings longer than 255 characters and #VALUE! for calculated references into a closed workbook. Leading or trailing spaces can also change a text match. The current implementation’s criteria and Unicode coverage limits are separate from those documented worksheet behaviours.
How to implement
- Resolve a single-area range reference. The current implementation requires a reference; a supplied array value is a distinct route and is not silently turned into one.
- Read the criterion once. Dereference a one-cell criterion reference. Keep numeric, logical, error, empty and text criteria as different kinds; an empty criterion cell becomes numeric zero.
- For text, recognize the longest leading operator first:
<=,>=,<>, then<,>,=. Missing operator means equality. Parse the remaining operand as an error literal, a wildcard pattern, an admitted number or logical, or ordinary text under the current rules. - Match each cell with that typed predicate and count matches. Patterns need
*,?and tilde escaping with the supported case mapping. Blank cells and empty strings must remain distinct until the predicate chooses their verdict. - Return the count as a number. Do not evaluate the criterion string as arbitrary formula code.
For the numeric example, four and seven fail >=10, while eleven and thirteen pass. The interval expression counts three values at least seven, then subtracts the one above eleven, leaving two.
The current code limits criterion text to 255 UTF-16 code units and refuses some unresolved collation, text-coercion and array-criterion cases. A typed implementation refusal reports an unsupported case; it is not evidence that Excel returns a worksheet error there. Error-valued criteria also need their own predicate handling rather than an unconditional exception path.
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.
COUNTIF · 1 lines · calc-func/src/catalogue/conditional.rs on GitHubconditional(COUNTIF, "COUNTIF", (2, 2), RANGE_CRITERIA, countif)
countif · 11 lines · calc-func/src/catalogue/conditional.rs on GitHub/// COUNTIF: the cells of the range that meet the criterion.
fn countif(
arguments: &[CalcValue],
services: &mut EvalServices<'_>,
) -> Result<CalcValue, FunctionFault> {
let site = Site::new(COUNTIF, services);
Site::finish(single(&site, arguments, services, false).and_then(|plan| {
let conditions = plan.read_conditions(&site, services)?;
count(&site, &conditions, plan.size)
}))
}
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/conditionalRange::shapecatalogue/conditionalrangecatalogue/conditionalsinglecatalogue/conditionalPlan::read_conditionscatalogue/conditionalrowcatalogue/conditionalcountcatalogue/conditionaloffsetcatalogue/conditionalread_rangecatalogue/conditionalverdictscatalogue/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 same-input comparison between named Excel builds is recorded for this function here. The documented behaviour below is not a measurement of every Excel release.
Alternatives
COUNTIFS combines conditions with AND. For OR conditions, account for overlap when adding separate counts. FILTER returns matching rows.
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents