{
  "category": "Statistical functions",
  "display_name": "RANK.EQ",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.RANK.EQ",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 5 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 5 recorded answers",
    "workbook_corpus": {
      "cells": 5,
      "matched": 5
    }
  },
  "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/statistics.rs#L300-L300"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/statistics::list",
        "catalogue/statistics::rank_number",
        "catalogue/statistics::rank",
        "ported/rank_common::rank_eq",
        "ported/rank_common::rank_avg"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/statistics.rs#L300-L300",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 5 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.RANK.EQ.json",
  "name": "RANK.EQ",
  "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- **[RANK.AVG](FUNC.RANK.AVG.md)** is the sibling that resolves ties by averaging. For a tied\n  block of `m` values starting at competition rank `r`, `RANK.AVG` returns `r + (m-1)/2`, the\n  midrank. The two functions agree exactly when `number` has no duplicates in `ref`. `RANK.AVG`\n  is the one to use whenever the ranks feed further statistics, because its ranks always sum to\n  `n(n+1)/2`.\n- **`RANK`** is the legacy Compatibility-category name. Microsoft's replacement\n  guidance points `RANK` at `RANK.EQ`, and the two are documented as computing the same quantity.\n  **The Handbook does not treat that as an identity.** A legacy alias and its modern name are two\n  registered entry points, and Excel is free to route them to two different code paths; that they\n  agree is a claim requiring evidence. No such evidence is in the Handbook's record. The one\n  place the question has teeth is the `order` flag and the non-numeric-`number` case, where the\n  older function's behaviour is even less documented.\n- **[SMALL](FUNC.SMALL.md) and [LARGE](FUNC.LARGE.md)** are the inverses:\n  `LARGE(ref, RANK.EQ(x, ref))` recovers `x` when `x` occurs in `ref`, because competition rank\n  and the descending order-statistic index are the same number. The corresponding identity for\n  `RANK.AVG` fails on ties, since its rank need not be an integer.\n- **`PERCENTRANK.INC`** answers the same question on a `[0, 1]` scale\n  and *does* interpolate for values not present, which is exactly the behaviour `RANK.EQ` refuses.\n- **`COUNTIF`** reproduces the definition directly:\n  `COUNTIF(ref, \">\"&number) + 1` is the descending rank, without the presence check. Readers who\n  want a rank for an absent value write this, and should know they have given up the `#N/A`\n  diagnostic in the process.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n`RANK.EQ` performs no arithmetic beyond counting, so there is no rounding error anywhere in it.\nEvery numerical question about this function is a **comparison** question, and there are two.\n\n**Signed zero and the strict comparison.** `-0.0 == 0.0` is true and `-0.0 > 0.0` is false, so\nthe two zeros are one value for both the match test and the rank count. That is the right answer\nand it is worth noting only because the sort-free formulation makes it automatic — an\nimplementation that sorted and then scanned would have to be careful, and this one does not sort\nat all.\n\n**The counting form is `O(n)` per call and exact.** Because the rank is computed as a count\nrather than by sorting and locating, a column of `RANK.EQ` formulas over the same `ref` is\n`O(n^2)` overall. That is a performance fact rather than a correctness one, but it is the reason\nlarge rank columns are slow, and it is not fixable inside the function.\n\n**The `order` truncation.** `trunc(order)` before the zero test means the ascending/descending\nboundary is not at zero but across the open interval `(-1, 1)`, which all truncates to `0` and\ntherefore selects descending. Nothing documents this, and a caller passing a computed fraction\ngets the opposite of what the \"any nonzero value\" phrasing promises.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Number` — a positive integer, always an exact integer value.\n\n- **`number` not present in `ref`.** `#N/A`.\n- **`ref` empty of numbers.** `#N/A`.\n- **`number` present more than once.** All occurrences receive the same rank; the multiplicity\n  affects the ranks of *later* values, not this one.\n- **`number` in `ref` but reached by a different route.** The match is exact IEEE-754 equality of\n  the collected doubles — see Numerical notes. A value that displays identically but differs in\n  the last bit does not match.\n- **Errors in `ref`** propagate as themselves.\n- **`ref` given as a rectangular grid** is flattened; `RANK.EQ` does not care about shape.\n\n\n",
    "sources": "- Microsoft, *RANK.EQ function* —\n  <https://support.microsoft.com/en-us/office/rank-eq-function-284858ce-8ef6-450e-b662-26245be04a40>\n  (signature, the descending default and the zero/nonzero `order` convention, the shared-rank tie\n  behaviour, and the `#N/A` condition when `number` is absent). Retrieval was blocked by the\n  upstream host for this page; the documented behaviour above is stated as documented behaviour\n  and should be re-checked against the page.\n- Handbook [coercion and lifting](../model/02-coercion-and-lifting.md) — the range-scan policy\n  governing what `ref` contributes.\n- Handbook `data/functions/FUNC.RANK.EQ.json`, `data/presence/FUNC.RANK.EQ.json`.\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`RANK.EQ(number, ref, [order])` returns the position `number` would occupy in `ref` if `ref` were\nsorted, counting from the best end.\n\nLet `S = {v_1, …, v_n}` be the numeric values in `ref` (a multiset — repeats are kept). Then\n\n    order = 0 or omitted (descending):   RANK.EQ  =  #{ i : v_i >  number }  +  1\n    order nonzero      (ascending):      RANK.EQ  =  #{ i : v_i <  number }  +  1\n\nThe rank is a **strict count plus one**. That single formula is the whole function, and it\ndetermines the tie behaviour without any separate rule: because the comparison is strict, every\nmember of a tied block counts zero of its own peers, so all of them receive the same rank — the\nbest one the block occupies.\n\nThis is **competition ranking**, the `1, 2, 2, 4` convention. It is what a scoreboard does: two\nsilver medals and no bronze. Two properties follow, and the second is the one that surprises\npeople:\n\n1. **Ties share the best rank of their block.** Three values tied at what would be positions\n   `4, 5, 6` all rank `4`.\n2. **The ranks are not a permutation of `1..n`.** After a block of `m` ties at rank `r`, the next\n   distinct value ranks `r + m`, not `r + 1`. Ranks are skipped, and the sum of the ranks over\n   all of `ref` is not `n(n+1)/2`. Anything downstream that assumes a rank vector is a\n   permutation — a Spearman correlation computed by hand, for instance — is wrong on tied data\n   and needs [RANK.AVG](FUNC.RANK.AVG.md) instead.\n\n`number` must **occur** in `ref`. `RANK.EQ` is not an interpolating position function: it does\nnot tell you where a value *would* go, it tells you where a value that is present *is*. A\n`number` absent from `ref` yields `#N/A`, not a fractional or bracketing rank. That is the\nbehaviour that distinguishes `RANK.EQ` from `PERCENTRANK.INC`, which\ndoes interpolate.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Default |\n|---|---|---|\n| `number` | The value whose rank is wanted. Required. | — |\n| `ref` | The list of numbers to rank within. Required. | — |\n| `order` | `0` or omitted for descending; any nonzero value for ascending. Optional. | `0` (descending) |\n\nThe default is **descending**, which is worth stating explicitly because it is the opposite of\nthe default a reader coming from a sort dialog expects. `RANK.EQ(x, A)` answers \"how high does\n`x` place\", with `1` meaning largest.\n\n`ref` is consumed by scanning: text, logical values and blank cells in a scanned range are\nskipped rather than converted, so `n` counts numeric cells only. See\n[coercion and lifting](../model/02-coercion-and-lifting.md).\n\n\n"
  },
  "signature": {
    "display": "RANK.EQ(number, ref, [order])",
    "parameters": [
      {
        "description": null,
        "name": "number",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "ref",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "order",
        "optional": true,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 3,
        "min": 2
      },
      "category": "Statistical 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": "Rank of a number in a list, with tied values sharing the top rank",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the rank of a number in a list of numbers",
        "microsoft_url": "https://support.microsoft.com/en-us/office/rank-eq-function-284858ce-8ef6-450e-b662-26245be04a40"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "RANK.EQ"
        },
        {
          "locale": "bg-BG",
          "name": "RANK.EQ"
        },
        {
          "locale": "cs-CZ",
          "name": "RANK.EQ"
        },
        {
          "locale": "da-DK",
          "name": "PLADS.LIGE"
        },
        {
          "locale": "de-DE",
          "name": "RANK.EQ"
        },
        {
          "locale": "el-GR",
          "name": "RANK.EQ"
        },
        {
          "locale": "en-AU",
          "name": "RANK.EQ"
        },
        {
          "locale": "en-GB",
          "name": "RANK.EQ"
        },
        {
          "locale": "en-US",
          "name": "RANK.EQ"
        },
        {
          "locale": "es-ES",
          "name": "JERARQUIA.EQV"
        },
        {
          "locale": "et-EE",
          "name": "RANK.EQ"
        },
        {
          "locale": "fi-FI",
          "name": "ARVON.MUKAAN.TASAN"
        },
        {
          "locale": "fr-FR",
          "name": "EQUATION.RANG*"
        },
        {
          "locale": "he-IL",
          "name": "RANK.EQ"
        },
        {
          "locale": "hr-HR",
          "name": "RANK.EQ"
        },
        {
          "locale": "hu-HU",
          "name": "RANG.EGY"
        },
        {
          "locale": "id-ID",
          "name": "RANK.EQ"
        },
        {
          "locale": "it-IT",
          "name": "RANK.EQ"
        },
        {
          "locale": "ja-JP",
          "name": "RANK.EQ"
        },
        {
          "locale": "ko-KR",
          "name": "RANK.EQ"
        },
        {
          "locale": "lt-LT",
          "name": "RANK.EQ"
        },
        {
          "locale": "lv-LV",
          "name": "RANK.EQ"
        },
        {
          "locale": "nb-NO",
          "name": "RANG.EKV"
        },
        {
          "locale": "nl-NL",
          "name": "RANG.GELIJK"
        },
        {
          "locale": "pl-PL",
          "name": "POZYCJA.NAJW"
        },
        {
          "locale": "pt-BR",
          "name": "RANK.EQ"
        },
        {
          "locale": "pt-PT",
          "name": "ORDEM.EQ"
        },
        {
          "locale": "ro-RO",
          "name": "RANK.EQ"
        },
        {
          "locale": "ru-RU",
          "name": "РАНГ.РВ"
        },
        {
          "locale": "sk-SK",
          "name": "RANK.EQ"
        },
        {
          "locale": "sl-SI",
          "name": "RANK.EQ"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "RANK.EQ"
        },
        {
          "locale": "sv-SE",
          "name": "RANG.EKV"
        },
        {
          "locale": "th-TH",
          "name": "RANK.EQ"
        },
        {
          "locale": "tr-TR",
          "name": "RANK.EŞİT"
        },
        {
          "locale": "uk-UA",
          "name": "RANK.EQ"
        },
        {
          "locale": "vi-VN",
          "name": "RANK.EQ"
        },
        {
          "locale": "zh-CN",
          "name": "RANK.EQ"
        },
        {
          "locale": "zh-HK",
          "name": "RANK.EQ"
        },
        {
          "locale": "zh-TW",
          "name": "RANK.EQ"
        }
      ],
      "signature": {
        "display": "RANK.EQ(number, ref, [order])",
        "parameters": [
          {
            "description": null,
            "name": "number",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "ref",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "order",
            "optional": true,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "RANK.EQ",
      "version_marker": null,
      "xlcall": {
        "code": "509",
        "symbol": "xlfRank_eq"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/rank-eq-function-284858ce-8ef6-450e-b662-26245be04a40"
  },
  "try_it": {
    "formula": "=RANK.EQ(2,B2:B5)",
    "inputs": {
      "B2": 1,
      "B3": 2,
      "B4": 3,
      "B5": 4
    }
  },
  "url": "https://handbook.dnacalc.com/functions/RANK.EQ.html",
  "variants": [],
  "versions": []
}