---
title: with_bounds() | Tiger Data Docs
description: Add bounds to a counter aggregate
---

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

Add time bounds to an already-computed counter aggregate. Bounds are necessary to use extrapolation accessors on the aggregate.

## Samples

Create a counter aggregate for each `id` and each 15-minute interval. Then add bounds to the counter aggregate, so you can calculate the extrapolated rate.

```
SELECT
    id,
    bucket,
    extrapolated_rate(
        with_bounds(
            summary,
            time_bucket_range('15 min'::interval, bucket)
        ),
        'prometheus'
    )
FROM (
    SELECT
        id,
        time_bucket('15 min'::interval, ts) AS bucket,
        counter_agg(ts, val) AS summary
    FROM foo
    GROUP BY id, time_bucket('15 min'::interval, ts)
) t
```

## Arguments

The syntax is:

```
with_bounds(
    summary CounterSummary,
    bounds TSTZRANGE,
) RETURNS CounterSummary
```

| Name      | Type             | Default | Required | Description                                                                                                                     |
| --------- | ---------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `summary` | `CounterSummary` | -       | ✔        | A counter aggregate created using [`counter_agg`](/docs/reference/toolkit/counters-and-gauges/counter_agg/counter_agg/index.md) |
| `bounds`  | `TSTZRANGE`      | -       | ✔        | A range of `timestamptz` giving the smallest and largest allowed times in the counter aggregate                                 |

## Returns

| Column       | Type           | Description                                     |
| ------------ | -------------- | ----------------------------------------------- |
| with\_bounds | CounterSummary | A new counter aggregate with the bounds applied |
