{
  "category": "Our 10 featured functions",
  "display_name": "FILTER",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.FILTER",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 42 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 42 recorded answers",
    "workbook_corpus": {
      "cells": 42,
      "matched": 42
    }
  },
  "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/arrays.rs#L633-L636",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/ported/dynamic_array_reshape_family.rs#L222-L229",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/ported/dynamic_array_reshape_family.rs#L629-L670",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/ported/dynamic_array_reshape_family.rs#L672-L722"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/arrays::source_error",
        "catalogue/arrays::prepared",
        "catalogue/arrays::prepared_one",
        "catalogue/arrays::result",
        "catalogue/arrays::run",
        "ported/dynamic_array_reshape_family::scalar_cell",
        "ported/dynamic_array_reshape_family::materialize_array_arg",
        "ported/dynamic_array_reshape_family::shape",
        "ported/dynamic_array_reshape_family::get",
        "ported/dynamic_array_reshape_family::build_array",
        "ported/dynamic_array_reshape_family::map_dynamic_array_reshape_error_to_ws"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/arrays.rs#L633-L636",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 42 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.FILTER.json",
  "name": "FILTER",
  "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- **`SORT` and `UNIQUE`** are the other two members of the classic dynamic-array trio;\n  `FILTER` then `SORT` then `UNIQUE` is the canonical query pipeline, and all three live in the\n  same reference-implementation module.\n- **`CHOOSEROWS` / `CHOOSECOLS`** select by index where `FILTER` selects by predicate. When the\n  predicate is really \"positions 1, 4 and 9\", the index functions say it directly.\n- **`TAKE` / `DROP`** select contiguous edge bands, which is the other common special case.\n- **Advanced Filter and the database functions (`DSUM` and family)** are the pre-dynamic-array\n  answers to the same question, with criteria expressed as a range of criteria rows rather than\n  as a boolean array.\n- **`XLOOKUP`** answers \"the one matching row\" where `FILTER` answers \"all matching rows\".\n  Reaching for `FILTER` and then taking the first row is a common but weaker idiom, because it\n  computes everything to use one.\n- **`SUMIFS` / `COUNTIFS`** aggregate under criteria without materializing the matching rows;\n  when you only want a total, they do less work and produce no spill.\n\n\n",
    "how-to-implement": "\n### Notes for implementers\n\n- **Axis inference from `include`'s shape is the crux.** The rule has to distinguish a\n  column-shaped criterion from a row-shaped one, and to reject anything that is neither — with\n  `#VALUE!`, per the documentation. A 1×1 criterion is ambiguous for a 1×1 array and needs a\n  declared policy.\n- **The empty result must be intercepted before the array is constructed**, exactly as in\n  `DROP`: a zero-row array is not representable, so the `if_empty`-or-`#CALC!` decision belongs\n  at the point where the survivor count is known.\n- **Truth-value interpretation of `include` is per-family policy**, not engine law. The shared\n  model is explicit that to-logical behaviour is distributed across functions rather than\n  centralized, so an implementation must declare its rule for numbers, text, blanks and errors\n  in the criterion rather than inheriting one.\n- **Stability.** Preserving input order is part of the semantics, not an implementation\n  accident; any parallel or partitioned implementation must be order-preserving.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturn kind: `Array` — the surviving rows (or columns), spilled. The result's width equals\n`array`'s width when filtering rows, and its height equals `array`'s height when filtering\ncolumns.\n\n- **Every row passes** — the result equals the input.\n- **Exactly one row passes** — a one-row array, not a scalar. Downstream code that expects a\n  scalar should not assume; use `@` or a reducer.\n- **No row passes** — the empty case, handled by `if_empty` or by `#CALC!` (below).\n- **Errors inside `include`** are a different matter: an error in the criterion array has no\n  truth value. What `FILTER` does with one is not established here, and it is a case real\n  workbooks hit constantly, because criterion arrays are usually computed.\n- **A `FILTER` over a whole-column reference** carries the whole column's blanks into the\n  criterion, which is why the idiom is usually paired with a non-blank test.\n\n\n\n### Errors\n\n\nMicrosoft's page documents two conditions:\n\n- `#CALC!` when no entries in `include` are true and `if_empty` is omitted. This is the\n  empty-array case: the value model admits no empty array at the published boundary\n  ([value universe](../model/01-value-universe.md)), so \"nothing matched\" has to surface as an\n  error unless you supplied a substitute.\n- `#VALUE!` when `include` is not of a dimension compatible with `array`.\n\nThe `#CALC!` case is the one that changes how formulas must be written: any `FILTER` whose\ncriterion depends on data should either carry an `if_empty` or be wrapped. Note that `FILTER`\nis unusual in the reshape family for offering `if_empty` at all — `DROP` and its siblings give\nyou `#CALC!` with no substitute.\n\nAn error value supplied as an argument propagates under the universal rule in\n[coercion and lifting](../model/02-coercion-and-lifting.md).\n\n\n",
    "sources": "\n- Microsoft, FILTER function —\n  <https://support.microsoft.com/en-us/office/filter-function-f4f7cb66-82eb-4767-8f7c-4877ad80c759>\n  (argument definitions, the `if_empty` substitute, the `#CALC!` empty-result condition, and the\n  `#VALUE!` dimension-incompatibility condition).\n- Handbook `content/model/01-value-universe.md` (`#CALC!`; no empty array at the published\n  boundary).\n- Handbook `content/model/02-coercion-and-lifting.md` (to-logical as per-family policy;\n  elementwise lifting of comparisons; error propagation).\n- Handbook `content/model/03-call-pipeline.md` (`ValuesOnlyPreAdapter`; host-side spill\n  adaptation).\n- Handbook `data/functions/FUNC.FILTER.json` and `data/presence/FUNC.FILTER.json` (arity,\n  category placement, classification axes, shared reshape-family module).\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`FILTER(array, include, [if_empty])` keeps the slices of `array` for which the corresponding\nelement of `include` is true, and drops the rest. Order is preserved: the surviving slices come\nback in their original sequence.\n\nThe word doing the work is *slices*. `FILTER` does not select individual cells; it selects whole\nrows or whole columns, and **which axis it filters is decided by the shape of `include`, not by\nan argument**:\n\n- `include` shaped like a single column with one entry per row of `array` — rows are filtered;\n- `include` shaped like a single row with one entry per column of `array` — columns are\n  filtered.\n\nThat is the single most important thing to understand about this function, and it is the source\nof most `#VALUE!` results people meet with it: the criterion array must be parallel to the axis\nyou mean to filter, and getting it transposed does not filter the other way, it fails.\n\n`include` is an array of truth values, typically produced by a comparison over a range —\n`(A2:A100=\"North\")` — which is itself an elementwise lifted operation\n([coercion and lifting](../model/02-coercion-and-lifting.md)). Combining criteria is arithmetic\non those arrays: `*` for AND, `+` for OR. `FILTER` supplies no criteria language of its own,\nwhich is why it composes so freely and why it has no equivalent of the `COUNTIF` family's\ncriteria strings.\n\n\n\n### Arguments\n\n\n| Argument | Meaning |\n|---|---|\n| `array` | The array or range to filter. Required. |\n| `include` | A boolean array parallel to the filtered axis of `array`. Required. |\n| `if_empty` | The value to return when nothing passes the filter. Optional. |\n\nNotes on each:\n\n- **`array`** is prepared under `ValuesOnlyPreAdapter`, so a reference is resolved to its values\n  before the function runs; the result is values and carries no reference structure.\n- **`include`** must have exactly one entry per row (or per column) of `array`. Non-logical\n  values are interpreted by ordinary to-logical rules — zero is false, non-zero true — but which\n  contexts accept text logicals is per-family policy in the shared model rather than a universal\n  rule, and the Handbook has not established `FILTER`'s policy.\n- **`if_empty`** is the argument people omit and then wish they had not. Without it, an empty\n  result is an error (below). With it, `FILTER(…, …, \"\")` or `FILTER(…, …, \"none\")` degrades\n  gracefully. It accepts any scalar; whether it accepts an array is not established here.\n\n\n"
  },
  "signature": {
    "display": "FILTER(array, include, [if_empty])",
    "parameters": [
      {
        "description": null,
        "name": "array",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "include",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "if_empty",
        "optional": true,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 3,
        "min": 2
      },
      "category": "Our 10 featured functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "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": "The rows or columns of an array for which a condition holds",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Use this function to filter a range of data based on criteria you define.",
        "microsoft_url": "https://support.microsoft.com/en-us/office/filter-function-f4f7cb66-82eb-4767-8f7c-4877ad80c759"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "FILTER"
        },
        {
          "locale": "bg-BG",
          "name": "FILTER"
        },
        {
          "locale": "cs-CZ",
          "name": "FILTER"
        },
        {
          "locale": "da-DK",
          "name": "FILTRER"
        },
        {
          "locale": "de-DE",
          "name": "FILTER"
        },
        {
          "locale": "el-GR",
          "name": "FILTER"
        },
        {
          "locale": "en-AU",
          "name": "FILTER"
        },
        {
          "locale": "en-GB",
          "name": "FILTER"
        },
        {
          "locale": "en-US",
          "name": "FILTER"
        },
        {
          "locale": "es-ES",
          "name": "FILTRAR"
        },
        {
          "locale": "et-EE",
          "name": "FILTER"
        },
        {
          "locale": "fi-FI",
          "name": "SUODATA"
        },
        {
          "locale": "fr-FR",
          "name": "FILTRE*"
        },
        {
          "locale": "he-IL",
          "name": "FILTER"
        },
        {
          "locale": "hr-HR",
          "name": "FILTER"
        },
        {
          "locale": "hu-HU",
          "name": "SZŰRŐ"
        },
        {
          "locale": "id-ID",
          "name": "FILTER"
        },
        {
          "locale": "it-IT",
          "name": "FILTER"
        },
        {
          "locale": "ja-JP",
          "name": "FILTER"
        },
        {
          "locale": "ko-KR",
          "name": "FILTER"
        },
        {
          "locale": "lt-LT",
          "name": "FILTER"
        },
        {
          "locale": "lv-LV",
          "name": "FILTER"
        },
        {
          "locale": "nb-NO",
          "name": "FILTER"
        },
        {
          "locale": "nl-NL",
          "name": "FILTER"
        },
        {
          "locale": "pl-PL",
          "name": "FILTRUJ"
        },
        {
          "locale": "pt-BR",
          "name": "FILTER"
        },
        {
          "locale": "pt-PT",
          "name": "FILTRAR"
        },
        {
          "locale": "ro-RO",
          "name": "FILTER"
        },
        {
          "locale": "ru-RU",
          "name": "ФИЛЬТР"
        },
        {
          "locale": "sk-SK",
          "name": "FILTER"
        },
        {
          "locale": "sl-SI",
          "name": "FILTER"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "FILTER"
        },
        {
          "locale": "sv-SE",
          "name": "FILTER"
        },
        {
          "locale": "th-TH",
          "name": "FILTER"
        },
        {
          "locale": "tr-TR",
          "name": "FİLTRE"
        },
        {
          "locale": "uk-UA",
          "name": "FILTER"
        },
        {
          "locale": "vi-VN",
          "name": "FILTER"
        },
        {
          "locale": "zh-CN",
          "name": "FILTER"
        },
        {
          "locale": "zh-HK",
          "name": "FILTER"
        },
        {
          "locale": "zh-TW",
          "name": "FILTER"
        }
      ],
      "signature": {
        "display": "FILTER(array, include, [if_empty])",
        "parameters": [
          {
            "description": null,
            "name": "array",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "include",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "if_empty",
            "optional": true,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "FILTER",
      "version_marker": null,
      "xlcall": null
    },
    "microsoft": "https://support.microsoft.com/en-us/office/filter-function-f4f7cb66-82eb-4767-8f7c-4877ad80c759"
  },
  "try_it": {
    "formula": "=FILTER({1;2;3},{TRUE;FALSE;TRUE})"
  },
  "url": "https://handbook.dnacalc.com/functions/FILTER.html",
  "variants": [],
  "versions": []
}