> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# stats_agg() (two variables)

> Aggregate data into an intermediate statistical aggregate form for further calculation

<Icon icon="tag" iconType="duotone" /> Since [1.3.0][toolkit-1.3.0]

Aggregate data into an intermediate statistical aggregate form for further calculation. This is the first step for
performing any statistical aggregate calculations on two-dimensional data. Use `stats_agg` to create an intermediate
aggregate (`StatsSummary2D`) from your data. This intermediate form can then be used by one or more accessors in this
group to compute the final results. Optionally, multiple such intermediate aggregate objects can be combined using
`rollup()` or `rolling()` before an accessor is applied.

## Arguments

The syntax is:

```sql theme={"dark"}
stats_agg(
    y DOUBLE PRECISION,
    x DOUBLE PRECISION
) RETURNS StatsSummary2D
```

| Name | Type             | Default | Required | Description                                        |
| ---- | ---------------- | ------- | -------- | -------------------------------------------------- |
| y, x | DOUBLE PRECISION | -       | ✔        | The variables to use for the statistical aggregate |

## Returns

| Column     | Type           | Description                                                                                                                                                                                                                                                                                                    |
| ---------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| stats\_agg | StatsSummary2D | The statistical aggregate, containing data about the variables in an intermediate form. Pass the aggregate to accessor functions in the statistical aggregates API to perform final calculations. Or, pass the aggregate to rollup functions to combine multiple statistical aggregates into larger aggregates |

[toolkit-1.3.0]: https://github.com/timescale/timescaledb-toolkit/releases/tag/1.3.0
