{
  "category": "Math and trigonometry functions",
  "display_name": "AGGREGATE",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.AGGREGATE",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 8 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 8 recorded answers",
    "workbook_corpus": {
      "cells": 9,
      "matched": 8,
      "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/subtotal.rs#L197-L264"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/aggregate::reader",
        "catalogue/aggregate::read_reference",
        "catalogue/subtotal::held_values",
        "catalogue/subtotal::numbers_of",
        "catalogue/subtotal::compute",
        "ported/excel_numeric::excel_sqrt_staged",
        "ported/percentile_common::percentile_inc_kernel",
        "ported/percentile_common::percentile_exc_kernel",
        "ported/percentile_common::interpolate_sorted",
        "ported/variance_common::variance_from_values",
        "ported/variance_common::stdev_from_values"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/subtotal.rs#L197-L264",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 8 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.AGGREGATE.json",
  "name": "AGGREGATE",
  "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- **The nineteen selected functions** — each has its own Handbook page, and each is the authority\n  on what its own aggregation means. `AGGREGATE` changes *which values reach* those functions, not\n  what they compute.\n- **`IFERROR`, `ISERROR`, `IFNA`** — the pre-`AGGREGATE` idiom for error skipping, one cell at a\n  time.\n- **`FILTER`** and the dynamic-array functions — the modern alternative, which does the selecting\n  explicitly and then aggregates normally. Where `AGGREGATE`'s policy is a magic number, `FILTER`'s\n  is a visible predicate; that is usually the better formula, and it does not know about hidden\n  rows.\n- **`COUNTIFS` / `SUMIFS` / `AVERAGEIFS`** — criteria-based selection rather than\n  error-and-visibility-based selection. Different axis, frequently confused.\n- **Confused with**: `SUBTOTAL`, constantly, and by readers who assume `AGGREGATE`'s option 0 and\n  `SUBTOTAL`'s default behave alike.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n`AGGREGATE` has no numerics of its own — it computes nothing — but it fixes two things that are\nusually left implicit, and both belong on this page.\n\n**The skip changes the reduction, not the arithmetic.** Skipping error values removes terms from\nthe fold. Skipping hidden rows removes different terms. Neither reweights anything, so\n`AGGREGATE(1, 6, ...)` — average, ignoring errors — is the mean of the *surviving* values, with a\ndenominator that depends on how many errors there were. That is the intended reading, and it is\nworth stating because the alternative reading (treat errors as zero) would give a different and\nalso plausible answer.\n\n**Variance and standard deviation inherit their own hazard.** `function_num` 7, 8, 10 and 11 select\n`STDEV.S`, `STDEV.P`, `VAR.S`, `VAR.P`. Whether those are computed by the textbook\nsum-of-squares-minus-square-of-sum formula or by a numerically stable two-pass or Welford recurrence\nis a property of *those* functions, not of `AGGREGATE`, and it is the dominant accuracy question\nwhen the data has a large mean and a small spread. See those pages.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns whatever kind the selected aggregate returns — in practice `Number`, or an `Error`.\n\n| Axis | Value | What it means here |\n|---|---|---|\n| `arg_preparation_profile` | `RefsVisibleInAdapter` | The function sees references, not resolved values — it must, to know which rows are hidden |\n| `host_interaction_class` | `WorkbookState` | It reads state outside its arguments: row visibility |\n| `thread_safety_class` | `HostSerialized` | It cannot run on an arbitrary calculation thread |\n| `error_collapse_profile` | `ReductionFold` | Errors are folded through a reduction, not passed through |\n| `numerical_reduction_policy` | `SequentialLeftFold` | The reduction order is specified, left to right |\n| `error_algebra` | `CanonicalExcelLegacy` | Which error wins when several are present follows the legacy precedence |\n| `volatility_class` | `NonVolatile` | Despite reading workbook state, it is not declared volatile |\n\nThe last two rows deserve emphasis. `AGGREGATE` reads *hidden-row state*, which is presentation\nstate rather than cell content, and it is nevertheless classified non-volatile. That combination —\ndepends on workbook state, does not recalculate on every change — is the source of the practical\ncomplaint that `AGGREGATE` results can go stale after rows are hidden or shown, and it is a\nbehaviour worth probing rather than assuming.\n\n**\"Hidden\" means hidden rows.** The Learn documentation says rows throughout. Hidden *columns* are\nnot mentioned, and filtered-out rows versus manually hidden rows is a distinction the\ndocumentation does not draw here at all.\n\n\n\n### Errors\n\nEverything else — an out-of-range `function_num`, an out-of-range `options`, a `ref1` of the wrong\nkind for the selected function — is undocumented on the page that was retrieved. Those are on the\nprobe list below.\n\n\n",
    "sources": "- Microsoft Learn, \"WorksheetFunction.Aggregate method (Excel)\" —\n  <https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.aggregate> (retrieved:\n  the 1-19 `function_num` table, the 0-7 `options` table, the reference-type constraint table for\n  `function_num` 1-13 and 14-17, and the two documented `#VALUE!` conditions).\n- Higham, *Accuracy and Stability of Numerical Algorithms*, chapter 4 — summation error bounds and\n  what compensated summation buys.\n- Handbook projections `data/functions/FUNC.AGGREGATE.json` (arity 3-255,\n  `RefsVisibleInAdapter`, `WorkbookState`, `HostSerialized`, `ReductionFold`,\n  `numerical_reduction_policy=SequentialLeftFold`, `error_algebra=CanonicalExcelLegacy`) and\n  `data/presence/FUNC.AGGREGATE.json` (module shared with `FUNC.SUBTOTAL`; the `BUG-FUNC-011`\n  defect stream; the upstream family contract document).\n- Handbook [Coercion and lifting](../model/02-coercion-and-lifting.md) — `AGGREGATE` as the\n  declared exception to the no-silent-error-discard rule — and\n  [The value universe](../model/01-value-universe.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`AGGREGATE(function_num, options, ref1, [ref2], ...)` applies one of nineteen aggregate functions\nto its reference arguments, under an explicit policy about what to skip.\n\nIt is not one function but a dispatcher over a table. Microsoft's Learn reference documents the\nselector as a number from 1 to 19:\n\n| `function_num` | Function | | `function_num` | Function |\n|---|---|---|---|---|\n| 1 | `AVERAGE` | | 11 | `VAR.P` |\n| 2 | `COUNT` | | 12 | `MEDIAN` |\n| 3 | `COUNTA` | | 13 | `MODE.SNGL` |\n| 4 | `MAX` | | 14 | `LARGE` |\n| 5 | `MIN` | | 15 | `SMALL` |\n| 6 | `PRODUCT` | | 16 | `PERCENTILE.INC` |\n| 7 | `STDEV.S` | | 17 | `QUARTILE.INC` |\n| 8 | `STDEV.P` | | 18 | `PERCENTILE.EXC` |\n| 9 | `SUM` | | 19 | `QUARTILE.EXC` |\n| 10 | `VAR.S` | | | |\n\nand the second argument as an ignore policy, also documented on that page:\n\n| `options` | Behaviour |\n|---|---|\n| 0 or omitted | Ignore nested `SUBTOTAL` and `AGGREGATE` functions |\n| 1 | Ignore hidden rows, nested `SUBTOTAL` and `AGGREGATE` functions |\n| 2 | Ignore error values, nested `SUBTOTAL` and `AGGREGATE` functions |\n| 3 | Ignore hidden rows, error values, nested `SUBTOTAL` and `AGGREGATE` functions |\n| 4 | Ignore nothing |\n| 5 | Ignore hidden rows |\n| 6 | Ignore error values |\n| 7 | Ignore hidden rows and error values |\n\nThe two-bit structure is worth naming, because the table above is really a product: bit 0 is\n\"ignore hidden rows\", bit 1 is \"ignore error values\", and everything below 4 additionally ignores\nnested `SUBTOTAL` and `AGGREGATE` calls. Options `0`-`3` are the nesting-aware quadrant; `4`-`7`\nare the same four policies without the nesting rule.\n\n**What `AGGREGATE` is for** is the error-skipping column. Every other route to \"average this\ncolumn but ignore the `#N/A`s\" is an array formula or an `IFERROR` wrapper over each cell;\n`AGGREGATE` makes it argument 2. That is the reason the function exists, and it is why the\ncoercion chapter names `AGGREGATE` as the declared exception to the rule that coercion never\nsilently discards a worksheet error — see\n[Coercion and lifting](../model/02-coercion-and-lifting.md). The skipping is a per-family\ndeclaration, visible here, not an implicit engine behaviour.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Required |\n|---|---|---|\n| `function_num` | Which of the nineteen aggregates to apply | yes |\n| `options` | Which values to skip | yes at the worksheet call site; Microsoft documents `0` as the behaviour when it is omitted |\n| `ref1` | The first reference (or, for the order-statistic selectors, the data) | yes |\n| `ref2`, ... | Further references, or the `k` argument for the order-statistic selectors | no |\n\n### The argument position that catches everyone\n\nFor `function_num` 14 through 19 — `LARGE`, `SMALL`, `PERCENTILE.INC`, `QUARTILE.INC`,\n`PERCENTILE.EXC`, `QUARTILE.EXC` — the *second* reference argument is not more data. It is the\n`k` argument of the selected function. So `AGGREGATE(14, 6, A1:A100, 3)` is \"the third largest,\nignoring errors\", and the trailing `3` is a rank, not a range. For `function_num` 1 through 13 the\nsame slot *is* more data. One signature, two meanings, keyed on the first argument's value.\n\nMicrosoft's Learn reference documents the consequences of getting this wrong, and they are worth\nquoting in effect: if a second `ref` argument is required but not provided, `AGGREGATE` returns a\n`#VALUE!` error.\n\n### Reference types\n\nThe Learn page's constraint table is unusually specific, and it is where `AGGREGATE` departs\nsharply from ordinary aggregates:\n\n- For `function_num` 1-13, the reference arguments accept cell references, unions, intersections,\n  defined names and structured references, and **explicitly do not accept actual data or arrays**.\n- For `function_num` 14-17, arrays and literal data *are* accepted in the first two slots, and no\n  references are allowed from the third onward.\n\nSo `AGGREGATE(9, 6, {1,2,3})` is documented as invalid while `AGGREGATE(14, 6, {1,2,3}, 1)` is\ndocumented as valid. That is a real and unusual asymmetry, and it follows from the first group\nbeing reference-consuming aggregations while the second group needs a materialised list to sort.\n\n**A gap in that table worth recording**: it covers `function_num` 1-13 and 14-17 and **stops**.\n`function_num` 18 and 19 — `PERCENTILE.EXC` and `QUARTILE.EXC` — are in the selector table and\nabsent from the constraint table. Their reference-type rules are documented nowhere on the page.\n\n\n"
  },
  "signature": {
    "display": "AGGREGATE(function_num, options, ref1, [ref2], ...)",
    "parameters": [
      {
        "description": null,
        "name": "function_num",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "options",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "ref1",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "ref2",
        "optional": true,
        "repeats": true
      }
    ],
    "trailing_repeats": true
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 253,
        "min": 3
      },
      "category": "Math and trigonometry functions",
      "classification": {
        "arg_preparation_profile": "RefsVisibleInAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "ReductionFold",
        "fec_dependency_profile": "Composite",
        "host_interaction_class": "WorkbookState",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "Composite",
        "thread_safety_class": "HostSerialized",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "One of nineteen summaries (sum, average, percentile and more) of a range, optionally skipping errors, hidden rows and nested subtotals",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns an aggregate in a list or database",
        "microsoft_url": "https://support.microsoft.com/en-us/office/aggregate-function-43b9278e-6aa7-4f17-92b6-e19993fa26df"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "المجموع"
        },
        {
          "locale": "bg-BG",
          "name": "AGGREGATE"
        },
        {
          "locale": "cs-CZ",
          "name": "AGGREGATE"
        },
        {
          "locale": "da-DK",
          "name": "SAMLING"
        },
        {
          "locale": "de-DE",
          "name": "AGGREGAT"
        },
        {
          "locale": "el-GR",
          "name": "AGGREGATE"
        },
        {
          "locale": "en-AU",
          "name": "AGGREGATE"
        },
        {
          "locale": "en-GB",
          "name": "AGGREGATE"
        },
        {
          "locale": "en-US",
          "name": "AGGREGATE"
        },
        {
          "locale": "es-ES",
          "name": "AGREGAR"
        },
        {
          "locale": "et-EE",
          "name": "AGGREGATE"
        },
        {
          "locale": "fi-FI",
          "name": "KOOSTE"
        },
        {
          "locale": "fr-FR",
          "name": "AGRÉGAT*"
        },
        {
          "locale": "he-IL",
          "name": "AGGREGATE"
        },
        {
          "locale": "hr-HR",
          "name": "AGGREGATE"
        },
        {
          "locale": "hu-HU",
          "name": "ÖSSZESÍT"
        },
        {
          "locale": "id-ID",
          "name": "AGGREGATE"
        },
        {
          "locale": "it-IT",
          "name": "AGGREGATE"
        },
        {
          "locale": "ja-JP",
          "name": "AGGREGATE"
        },
        {
          "locale": "ko-KR",
          "name": "AGGREGATE"
        },
        {
          "locale": "lt-LT",
          "name": "AGGREGATE"
        },
        {
          "locale": "lv-LV",
          "name": "AGGREGATE"
        },
        {
          "locale": "nb-NO",
          "name": "AGGREGAT"
        },
        {
          "locale": "nl-NL",
          "name": "AGGREGATE"
        },
        {
          "locale": "pl-PL",
          "name": "AGREGUJ"
        },
        {
          "locale": "pt-BR",
          "name": "AGREGADO"
        },
        {
          "locale": "pt-PT",
          "name": "AGREGAR"
        },
        {
          "locale": "ro-RO",
          "name": "AGGREGATE"
        },
        {
          "locale": "ru-RU",
          "name": "АГРЕГАТ"
        },
        {
          "locale": "sk-SK",
          "name": "AGGREGATE"
        },
        {
          "locale": "sl-SI",
          "name": "ZDRUŽEVANJE"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "AGGREGATE"
        },
        {
          "locale": "sv-SE",
          "name": "AGGREGERA"
        },
        {
          "locale": "th-TH",
          "name": "AGGREGATE"
        },
        {
          "locale": "tr-TR",
          "name": "TOPLAMA işlevi"
        },
        {
          "locale": "uk-UA",
          "name": "AGGREGATE"
        },
        {
          "locale": "vi-VN",
          "name": "AGGREGATE"
        },
        {
          "locale": "zh-CN",
          "name": "AGGREGATE"
        },
        {
          "locale": "zh-HK",
          "name": "AGGREGATE"
        },
        {
          "locale": "zh-TW",
          "name": "AGGREGATE"
        }
      ],
      "signature": {
        "display": "AGGREGATE(function_num, options, ref1, [ref2], ...)",
        "parameters": [
          {
            "description": null,
            "name": "function_num",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "options",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "ref1",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "ref2",
            "optional": true,
            "repeats": true
          }
        ],
        "trailing_repeats": true
      },
      "surface_name": "AGGREGATE",
      "version_marker": null,
      "xlcall": {
        "code": "485",
        "symbol": "xlfAggregate"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/aggregate-function-43b9278e-6aa7-4f17-92b6-e19993fa26df"
  },
  "try_it": {
    "formula": "=AGGREGATE(9,6,B2:B4)",
    "inputs": {
      "B2": 1,
      "B3": 2,
      "B4": 3
    }
  },
  "url": "https://handbook.dnacalc.com/functions/AGGREGATE.html",
  "variants": [],
  "versions": []
}