{
  "category": "Math and trigonometry functions",
  "display_name": "SUMIF",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.SUMIF",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 32 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 32 recorded answers",
    "workbook_corpus": {
      "cells": 33,
      "matched": 32,
      "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#L167-L167",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/conditional.rs#L206-L216"
      ],
      "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::total",
        "catalogue/conditional::Range::shape",
        "catalogue/conditional::range",
        "catalogue/conditional::single",
        "catalogue/conditional::Plan::each_matched",
        "catalogue/conditional::row",
        "catalogue/conditional::offset",
        "catalogue/conditional::read_range",
        "catalogue/conditional::verdicts",
        "catalogue/conditional::target_cells",
        "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#L167-L167",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 32 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.SUMIF.json",
  "name": "SUMIF",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n\n- **`SUMIFS`** — the multi-criterion successor, and note the **argument order is different**:\n  `SUMIFS(sum_range, criteria_range1, criteria1, ...)` puts the summed range first, where\n  `SUMIF` puts it last. Converting one to the other by adding a criterion pair does not work;\n  the arguments have to be rearranged. `SUMIFS` also requires its ranges to match in shape rather\n  than reshaping from an anchor, which makes it the safer function even for a single criterion.\n- **`COUNTIF` / `COUNTIFS`** — the same predicate machinery with a counting reduction. `COUNTIF`\n  is a co-subject of the evidence record attached to this page.\n- **`AVERAGEIF` / `AVERAGEIFS`, `MAXIFS`, `MINIFS`** — the rest of the module.\n- **`SUMPRODUCT`** — the general alternative, whose conditions are arbitrary array expressions\n  rather than criteria strings. It is more general and less readable; `SUMIF` is the right tool\n  when the condition fits the criteria language.\n- **`FILTER` + `SUM`** — the modern dynamic-array route, which makes the matched set visible as\n  a value rather than hiding it inside the aggregation.\n- **`DSUM`** — the database-family equivalent, with criteria expressed as a range rather than as\n  a string.\n- **Confused with**: `SUMIFS` (argument order), and with `SUMIF` over a `sum_range` of the wrong\n  shape (the sizing rule above).\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n`SUMIF` has two numerical characters, and they are unrelated to each other.\n\nWhat that means for a reader of `SUMIF`: a criterion of `0.3` can match a stored value of\n`0.1+0.2`, even though those are different doubles. Whether you regard that as a bug or as the\nonly humane behaviour for a spreadsheet, it is a real semantic property and it changes which\ncells enter the sum. It also means the matched set is not determined by the bits alone, so two\nimplementations that agree on IEEE arithmetic can still disagree on `SUMIF`.\n\n**The record's counts are not this surface's counts.** `EV-STRUCT-0001` carries an explicit\nreader warning that its total is over hand-picked lanes spanning both arms, not a pass rate for\nany surface, and it records an unresolved discrepancy in the upstream lane enumeration. `SUMIF`\nappears there with the subject role `body-only`. **This page states none of those figures; the\nevidence layer renders them beside it with their warnings attached.**\n\n",
    "quirks": "\n### The sum_range sizing rule\n\n\nThis is the position most readers get wrong, and the documentation is explicit about it:\n\"Sum_range should be the same size and shape as range. If it isn't, performance may suffer, and\nthe formula will sum a range of cells that starts with the first cell in sum_range but has the\nsame dimensions as range.\"\n\nIn other words: **`sum_range` is treated as an anchor, not as an extent.** Only its top-left\ncell is honoured; the shape is taken from `range`. `SUMIF(A1:A10, \">5\", B1)` therefore sums\n`B1:B10`, and `SUMIF(A1:A10, \">5\", B1:B3)` also sums `B1:B10` — silently reading seven cells the\nauthor never named.\n\nThe consequences are worth stating plainly, because none of them produce an error:\n\n- A `sum_range` that is *shorter* than `range` reads past its own end into whatever lies below.\n- A `sum_range` whose orientation differs from `range` — a row where `range` is a column — is\n  re-shaped to `range`'s dimensions from its anchor, so the cells summed may have no relation to\n  the ones written in the formula.\n- Inserting or deleting rows inside `range` changes which cells `sum_range` covers, without\n  touching the `sum_range` reference at all.\n\nThe defensive practice is simply to write both ranges with identical shapes and to keep them\nadjacent, so a structural edit moves both together.\n\n\n\n### Result and edge cases\n\n\nReturns `Number`.\n\n- **No matches**: zero. `SUMIF` does not report an empty match set as an error, which means an\n  entirely mistyped criterion is indistinguishable from a genuine zero total.\n- **Text and logicals in `sum_range`**: not addressed on the `SUMIF` page. The aggregate family's\n  range-scan policy is the governing rule; see\n  [Coercion and lifting](../model/02-coercion-and-lifting.md#direct-arguments-versus-range-scans).\n  The Handbook has not checked which scan policy this surface uses.\n- **Numeric criteria matching is not exact IEEE equality.** This is the substantive finding on\n  this surface and it is discussed under *Numerical notes*.\n\n\n### Errors\n\n\n| Error | Condition | Source |\n|---|---|---|\n| `#VALUE!` | An argument does not resolve to a range or a usable criteria value | Shared call model; not enumerated on the `SUMIF` page |\n| propagated | An error value among the scanned data surfaces as that error | Shared coercion rules and the module's `ReductionFold` |\n\nMicrosoft's page documents no error conditions for `SUMIF`. It documents a *wrong-answer*\ncondition instead (the long-string limitation above), which is a different and arguably worse\nthing.\n\n\n",
    "sources": "\n- Microsoft, \"SUMIF function\" —\n  <https://support.microsoft.com/en-us/office/sumif-function-169b8c99-c05c-4483-a712-1697a653039b>\n  (signature; the argument descriptions; \"The SUMIF function returns incorrect results when you\n  use it to match strings longer than 255 characters\"; the wildcard set; the quotation-mark rule\n  for text and symbolic criteria; and the `sum_range` sizing rule quoted above).\n- Handbook evidence record `EV-STRUCT-0001` (subjects include `FUNC.SUMIF`, role `body-only`) —\n  the tolerant-versus-exact comparison family split, with its own reader warning and open\n  question.\n- Higham, *Accuracy and Stability of Numerical Algorithms* — summation error bounds and the\n  order dependence of a fold.\n- Handbook projections `data/functions/FUNC.SUMIF.json` (arity 2-3,\n  `error_collapse_profile: ReductionFold`, `numerical_reduction_policy=SequentialLeftFold`,\n  `arg_preparation_profile: RefsVisibleInAdapter`) and `data/presence/FUNC.SUMIF.json` (module\n  shared with `AVERAGEIF`, `AVERAGEIFS`, `COUNTIF`, `COUNTIFS`, `MAXIFS`, `MINIFS`, `SUMIFS`).\n- Handbook [Coercion and lifting](../model/02-coercion-and-lifting.md).\n\n",
    "version-differences": "No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.",
    "what-it-does": "\n`SUMIF(range, criteria, [sum_range])` adds the values of `sum_range` at the positions where\n`range` satisfies `criteria`. Written as a filtered reduction:\n\n    M   = { i : P(range_i) }            the matched index set\n    SUMIF = SUM over i in M of s_i      where s is sum_range, or range itself if omitted\n\nTwo things are worth separating in that definition, because the function's whole difficulty\nlives in the gap between them:\n\n1. **The predicate `P`** is applied to `range`. It is not an arbitrary expression; it is a\n   *criteria value* in the family's small criteria language — a number, a text string, a\n   comparison written as text (`\">5\"`), or a wildcard pattern.\n2. **The values summed** come from `sum_range`, a *different* range, addressed positionally\n   rather than by intersection. That indirection is the source of the sizing rule below.\n\nMicrosoft describes the arguments as the range \"you want evaluated by criteria\", the criteria\n\"in the form of a number, expression, a cell reference, text, or a function that defines which\ncells will be added\", and `sum_range` as \"the actual cells to add, if you want to add cells\nother than those specified in the range argument\".\n\n\n### Arguments\n\n\n| Argument | Meaning | Default |\n|---|---|---|\n| `range` | The cells evaluated by `criteria`. Required. | — |\n| `criteria` | The condition selecting which cells are added. Required. | — |\n| `sum_range` | The cells actually added. Optional. | `range` |\n\n**The criteria language, as documented.** Criteria may be a number, an expression, a cell\nreference, text, or a function. Text criteria and any criteria containing logical or\nmathematical symbols must be enclosed in double quotation marks — so `\">5\"` is a string that the\nfunction parses as a comparison, not a comparison the formula evaluates. Wildcards are\navailable: `?` matches a single character, `*` matches any sequence, and `~` escapes a literal\n`?` or `*`.\n\n**A documented limitation worth quoting for its unusual candour.** Microsoft states: \"The SUMIF\nfunction returns incorrect results when you use it to match strings longer than 255 characters.\"\nNot an error value — *incorrect results*. That is a documented silent-wrong-answer condition,\nand it is rare enough in Microsoft's function reference to be worth flagging: a formula matching\nlong strings is documented to produce a number that is simply not the right number, with no\ndiagnostic anywhere. Any workbook matching on long free-text keys is in that territory.\n\n\n"
  },
  "signature": {
    "display": "SUMIF(range, criteria, [sum_range])",
    "parameters": [
      {
        "description": null,
        "name": "range",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "criteria",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "sum_range",
        "optional": true,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 3,
        "min": 2
      },
      "category": "Math and trigonometry 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": "Total of the cells that meet one condition",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Adds the cells specified by a given criteria",
        "microsoft_url": "https://support.microsoft.com/en-us/office/sumif-function-169b8c99-c05c-4483-a712-1697a653039b"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "SUMIF"
        },
        {
          "locale": "bg-BG",
          "name": "SUMIF"
        },
        {
          "locale": "cs-CZ",
          "name": "SUMIF"
        },
        {
          "locale": "da-DK",
          "name": "SUM.HVIS"
        },
        {
          "locale": "de-DE",
          "name": "SUMMEWENN"
        },
        {
          "locale": "el-GR",
          "name": "SUMIF"
        },
        {
          "locale": "en-AU",
          "name": "SUMIF"
        },
        {
          "locale": "en-GB",
          "name": "SUMIF"
        },
        {
          "locale": "en-US",
          "name": "SUMIF"
        },
        {
          "locale": "es-ES",
          "name": "SUMAR.SI"
        },
        {
          "locale": "et-EE",
          "name": "Funktsioon SUMIF"
        },
        {
          "locale": "fi-FI",
          "name": "SUMMA.JOS"
        },
        {
          "locale": "fr-FR",
          "name": "SOMME.SI"
        },
        {
          "locale": "he-IL",
          "name": "SUMIF"
        },
        {
          "locale": "hr-HR",
          "name": "SUMIF"
        },
        {
          "locale": "hu-HU",
          "name": "SZUMHA"
        },
        {
          "locale": "id-ID",
          "name": "SUMIF"
        },
        {
          "locale": "it-IT",
          "name": "SOMMA.SE"
        },
        {
          "locale": "ja-JP",
          "name": "SUMIF"
        },
        {
          "locale": "ko-KR",
          "name": "SUMIF"
        },
        {
          "locale": "lt-LT",
          "name": "SUMIF"
        },
        {
          "locale": "lv-LV",
          "name": "SUMIF"
        },
        {
          "locale": "nb-NO",
          "name": "SUMMERHVIS"
        },
        {
          "locale": "nl-NL",
          "name": "SOM.ALS"
        },
        {
          "locale": "pl-PL",
          "name": "SUMA.JEŻELI"
        },
        {
          "locale": "pt-BR",
          "name": "SOMASE"
        },
        {
          "locale": "pt-PT",
          "name": "SOMA.SE"
        },
        {
          "locale": "ro-RO",
          "name": "SUMIF"
        },
        {
          "locale": "ru-RU",
          "name": "СУММЕСЛИ"
        },
        {
          "locale": "sk-SK",
          "name": "SUMIF"
        },
        {
          "locale": "sl-SI",
          "name": "SUMIF"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "SUMIF"
        },
        {
          "locale": "sv-SE",
          "name": "SUMMA.OM"
        },
        {
          "locale": "th-TH",
          "name": "SUMIF"
        },
        {
          "locale": "tr-TR",
          "name": "ETOPLA"
        },
        {
          "locale": "uk-UA",
          "name": "SUMIF"
        },
        {
          "locale": "vi-VN",
          "name": "SUMIF"
        },
        {
          "locale": "zh-CN",
          "name": "SUMIF"
        },
        {
          "locale": "zh-HK",
          "name": "SUMIF"
        },
        {
          "locale": "zh-TW",
          "name": "SUMIF"
        }
      ],
      "signature": {
        "display": "SUMIF(range, criteria, [sum_range])",
        "parameters": [
          {
            "description": null,
            "name": "range",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "criteria",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "sum_range",
            "optional": true,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "SUMIF",
      "version_marker": null,
      "xlcall": {
        "code": "345",
        "symbol": "xlfSumif"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/sumif-function-169b8c99-c05c-4483-a712-1697a653039b"
  },
  "try_it": {
    "formula": "=SUMIF(B2:B4,\">1\",C2:C4)",
    "inputs": {
      "B2": 1,
      "B3": 2,
      "B4": 3,
      "C2": 10,
      "C3": 20,
      "C4": 30
    }
  },
  "url": "https://handbook.dnacalc.com/functions/SUMIF.html",
  "variants": [],
  "versions": []
}