> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# $extendedStats

`$extendedStats` returns `$stats` plus additional distribution metrics.

In addition to `count`, `sum`, `min`, `max`, and `avg`, this operator provides:

* `sumOfSquares`
* `variance`, `variancePopulation`, `varianceSampling`
* `stdDeviation`, `stdDeviationPopulation`, `stdDeviationSampling`
* `stdDeviationBounds` (`upper`, `lower`, plus sampling/population variants)

`sigma` controls the width of `stdDeviationBounds`.

### Compatibility

| Field Type  | Supported |
| ----------- | --------- |
| TEXT        | No        |
| U64/I64/F64 | Yes       |
| DATE        | Yes       |
| BOOL        | No        |
| KEYWORD     | No        |
| FACET       | No        |

Field must be `FAST`.

### Arguments

| Argument  | Type     | Required | Description                                    |
| --------- | -------- | -------- | ---------------------------------------------- |
| `field`   | `string` | Yes      | Field to aggregate.                            |
| `missing` | `number` | No       | Fallback value for missing fields.             |
| `sigma`   | `number` | No       | Multiplier used for standard deviation bounds. |

<Tabs>
  <Tab title="TypeScript">
    ```ts theme={"system"}
    await index.aggregate({
      aggregations: {
        price_extended: {
          $extendedStats: { field: "price", sigma: 2, missing: 0 },
        },
      },
    });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={"system"}
    index.aggregate(
        aggregations={
            "price_extended": {
                "$extendedStats": {"field": "price", "sigma": 2, "missing": 0}
            }
        }
    )
    ```
  </Tab>

  <Tab title="Redis CLI">
    ```bash theme={"system"}
    SEARCH.AGGREGATE products '{}' '{"price_extended": {"$extendedStats": {"field": "price", "sigma": 2, "missing": 0}}}'
    ```
  </Tab>
</Tabs>

### Output

Returns a single object containing all basic and extended fields. Example shape:

```json theme={"system"}
{ "price_extended": {
    "count": 9, "min": 0, "max": 80, "avg": 40, "sum": 360,
    "sumOfSquares": 18000, "variance": 200, "stdDeviation": 14.14,
    "stdDeviationBounds": { "upper": 68.28, "lower": 11.72 }
  }
}
```
