---
title: rollup() | Tiger Data Docs
description: Combine multiple state aggregates
---

Early access [1.13.0](https://github.com/timescale/timescaledb-toolkit/releases/tag/1.13.0)

Combine multiple state aggregates into a single state aggregate. For example, you can use `rollup` to combine state aggregates from 15-minute buckets into daily buckets.

## Samples

Combine multiple state aggregates and calculate the duration spent in the `START` state.

```
WITH buckets AS (SELECT
    time_bucket('1 minute', ts) as dt,
    toolkit_experimental.compact_state_agg(ts, state) AS sa
FROM states_test
GROUP BY time_bucket('1 minute', ts))
SELECT toolkit_experimental.duration_in(
    'START',
    toolkit_experimental.rollup(buckets.sa)
)
FROM buckets;
```

## Arguments

The syntax is:

```
rollup(
    agg CompactStateAgg
) RETURNS CompactStateAgg
```

| Name | Type            | Default | Required | Description                                        |
| ---- | --------------- | ------- | -------- | -------------------------------------------------- |
| agg  | CompactStateAgg | -       | ✔        | State aggregates created using `compact_state_agg` |

## Returns

| Column | Type            | Description                                                    |
| ------ | --------------- | -------------------------------------------------------------- |
| agg    | CompactStateAgg | A new state aggregate that combines the input state aggregates |
