{
  "category": "Statistical functions",
  "display_name": "COUNTIF",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.COUNTIF",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 103 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 103 recorded answers",
    "workbook_corpus": {
      "cells": 104,
      "matched": 103,
      "pending": 1
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/conditional.rs#L165-L165",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/conditional.rs#L182-L192"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/aggregate::reader",
        "catalogue/aggregate::read_reference",
        "catalogue/comparison::numbers",
        "catalogue/comparison::in_band",
        "catalogue/comparison::Rounded::up",
        "catalogue/comparison::Roundings::of",
        "catalogue/comparison::Roundings::disjoint",
        "catalogue/comparison::texts",
        "catalogue/comparison/collation::compare",
        "catalogue/comparison/collation::weighed",
        "catalogue/comparison/collation::measured_iteration_extension",
        "catalogue/comparison/sort_key::table",
        "catalogue/comparison/sort_key::decode64",
        "catalogue/comparison/sort_key::Reader::byte",
        "catalogue/comparison/sort_key::Reader::varint",
        "catalogue/comparison/sort_key::Reader::done",
        "catalogue/comparison/sort_key::in_ranges",
        "catalogue/comparison/sort_key::build",
        "catalogue/comparison/sort_key::han_base",
        "catalogue/comparison/sort_key::derive",
        "catalogue/comparison/sort_key::shared_jamo_tails",
        "catalogue/comparison/sort_key::ordinary_jamo_prefix",
        "catalogue/comparison/sort_key::independent_jamo_suffix",
        "catalogue/comparison/sort_key::jamo_leading_primary",
        "catalogue/comparison/sort_key::leading_order",
        "catalogue/comparison/sort_key::Before::separate_special",
        "catalogue/comparison/sort_key::Gathered::kana",
        "catalogue/comparison/sort_key::Gathered::unit",
        "catalogue/comparison/sort_key::parts",
        "catalogue/comparison/sort_key::diacritic_order",
        "catalogue/comparison/sort_key::diacritics",
        "catalogue/conditional::conditional",
        "catalogue/conditional::Range::shape",
        "catalogue/conditional::range",
        "catalogue/conditional::single",
        "catalogue/conditional::Plan::read_conditions",
        "catalogue/conditional::row",
        "catalogue/conditional::count",
        "catalogue/conditional::offset",
        "catalogue/conditional::read_range",
        "catalogue/conditional::verdicts",
        "catalogue/conditional::used",
        "catalogue/conditional::Match::of",
        "catalogue/conditional::Match::negated",
        "catalogue/conditional::Op::holds",
        "catalogue/conditional::Op::is_equality",
        "catalogue/conditional::spells",
        "catalogue/conditional::criterion",
        "catalogue/conditional::rank",
        "catalogue/conditional::criterion_text",
        "catalogue/conditional::decided",
        "catalogue/conditional::Criterion::verdict",
        "catalogue/conditional::equality",
        "catalogue/conditional::is_surrogate",
        "catalogue/conditional::wildcard",
        "decimal::low32",
        "decimal::Natural::from_u64",
        "decimal::Natural::pow10",
        "decimal::Natural::normalize",
        "decimal::Natural::is_zero",
        "decimal::Natural::mul_add_small",
        "decimal::Natural::times_pow10",
        "decimal::Natural::times_pow5",
        "decimal::Natural::times_pow2",
        "decimal::ExactDecimal::binary",
        "ported/text_kernels::text",
        "ported/text_kernels::text_from_str",
        "ported/text_kernels::fold_unit",
        "ported/text_kernels::push_singleton_or_original",
        "ported/text_kernels::push_lower",
        "ported/text_kernels::lower"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/conditional.rs#L165-L165",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 103 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.COUNTIF.json",
  "name": "COUNTIF",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n[COUNTIFS](FUNC.COUNTIFS.md) combines conditions with AND. For OR conditions, account for overlap when adding separate counts. [FILTER](FUNC.FILTER.md) returns matching rows.\n\n\n",
    "how-to-implement": "\n1. 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.\n2. 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.\n3. 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.\n4. 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.\n5. Return the count as a number. Do not evaluate the criterion string as arbitrary formula code.\n\nFor 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.\n\nThe 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.\n\n\n",
    "quirks": "\nText 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.\n\nA 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.\n\nMicrosoft 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.\n\n\n",
    "sources": "\n- [Microsoft: COUNTIF function](https://support.microsoft.com/en-us/excel/get-started/use-the-countif-function-in-microsoft-excel), opened 6 November 2026; syntax, documented argument rules and errors.\n- [DnaCalc criteria grammar, range validation and count planning](https://github.com/DnaCalc/DnaCalc/blob/da3ecc4fb19a3a5529708c311d0e8f05688ac165/crates/calc-func/src/catalogue/conditional.rs); implementation rules and its explicit unsupported cases.\n\n",
    "try-it": "\nPut `4,11,7,13` in `B2:B5`:\n\n| Formula | Count | Why |\n|---|---:|---|\n| `=COUNTIF(B2:B5,\">=10\")` | 2 | Eleven and thirteen qualify |\n| `=COUNTIF(B2:B5,\">\"&B4)` | 2 | B4 supplies seven, so the criterion becomes `\">7\"` |\n| `=COUNTIF(B2:B5,\">=7\")-COUNTIF(B2:B5,\">11\")` | 2 | Include seven through eleven and remove larger values |\n\nFor 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.\n\n\n",
    "version-differences": "\nNo 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.\n\n\n",
    "what-it-does": "\n`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\"`.\n\n\n"
  },
  "signature": {
    "display": "COUNTIF(range, criteria)",
    "parameters": [
      {
        "description": null,
        "name": "range",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "criteria",
        "optional": false,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 2,
        "min": 2
      },
      "category": "Statistical functions",
      "classification": {
        "arg_preparation_profile": "RefsVisibleInAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "ReductionFold",
        "fec_dependency_profile": "RefOnly",
        "host_interaction_class": "None",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "How many cells meet one condition",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Counts the number of cells within a range that meet the given criteria",
        "microsoft_url": "https://support.microsoft.com/en-us/office/use-the-countif-function-in-microsoft-excel-e0de10c6-f885-4e71-abb4-1f464816df34"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "COUNTIF"
        },
        {
          "locale": "bg-BG",
          "name": "COUNTIF"
        },
        {
          "locale": "cs-CZ",
          "name": "COUNTIF"
        },
        {
          "locale": "da-DK",
          "name": "TÆL.HVIS"
        },
        {
          "locale": "de-DE",
          "name": "ZÄHLENWENN"
        },
        {
          "locale": "el-GR",
          "name": "COUNTIF"
        },
        {
          "locale": "en-AU",
          "name": "COUNTIF"
        },
        {
          "locale": "en-GB",
          "name": "COUNTIF"
        },
        {
          "locale": "en-US",
          "name": "COUNTIF"
        },
        {
          "locale": "es-ES",
          "name": "CONTAR.SI"
        },
        {
          "locale": "et-EE",
          "name": "COUNTIF."
        },
        {
          "locale": "fi-FI",
          "name": "LASKE.JOS"
        },
        {
          "locale": "fr-FR",
          "name": "NB.SI"
        },
        {
          "locale": "he-IL",
          "name": "COUNTIF"
        },
        {
          "locale": "hr-HR",
          "name": "COUNTIF"
        },
        {
          "locale": "hu-HU",
          "name": "DARABHA"
        },
        {
          "locale": "id-ID",
          "name": "COUNTIF"
        },
        {
          "locale": "it-IT",
          "name": "CONTA.SE"
        },
        {
          "locale": "ja-JP",
          "name": "COUNTIF"
        },
        {
          "locale": "ko-KR",
          "name": "COUNTIF"
        },
        {
          "locale": "lt-LT",
          "name": "COUNTIF"
        },
        {
          "locale": "lv-LV",
          "name": "COUNTIF"
        },
        {
          "locale": "nb-NO",
          "name": "ANTALL.HVIS"
        },
        {
          "locale": "nl-NL",
          "name": "AANTAL.ALS"
        },
        {
          "locale": "pl-PL",
          "name": "LICZ.JEŻELI"
        },
        {
          "locale": "pt-BR",
          "name": "CONT.SE"
        },
        {
          "locale": "pt-PT",
          "name": "CONTAR.SE"
        },
        {
          "locale": "ro-RO",
          "name": "COUNTIF"
        },
        {
          "locale": "ru-RU",
          "name": "СЧЁТЕСЛИ"
        },
        {
          "locale": "sk-SK",
          "name": "COUNTIF"
        },
        {
          "locale": "sl-SI",
          "name": "COUNTIF"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "COUNTIF"
        },
        {
          "locale": "sv-SE",
          "name": "ANTAL.OM"
        },
        {
          "locale": "th-TH",
          "name": "COUNTIF"
        },
        {
          "locale": "tr-TR",
          "name": "EĞERSAY"
        },
        {
          "locale": "uk-UA",
          "name": "COUNTIF"
        },
        {
          "locale": "vi-VN",
          "name": "COUNTIF"
        },
        {
          "locale": "zh-CN",
          "name": "COUNTIF"
        },
        {
          "locale": "zh-HK",
          "name": "COUNTIF"
        },
        {
          "locale": "zh-TW",
          "name": "COUNTIF"
        }
      ],
      "signature": {
        "display": "COUNTIF(range, criteria)",
        "parameters": [
          {
            "description": null,
            "name": "range",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "criteria",
            "optional": false,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "COUNTIF",
      "version_marker": null,
      "xlcall": {
        "code": "346",
        "symbol": "xlfCountif"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/use-the-countif-function-in-microsoft-excel-e0de10c6-f885-4e71-abb4-1f464816df34"
  },
  "try_it": {
    "formula": "=COUNTIF(B2:B5,\">=10\")",
    "inputs": {
      "B2": 4,
      "B3": 11,
      "B4": 7,
      "B5": 13
    }
  },
  "url": "https://handbook.dnacalc.com/functions/COUNTIF.html",
  "variants": [],
  "versions": []
}