---
title: Gauge aggregation overview | Tiger Data Docs
description: Functions for analyzing gauge metrics that can increase or decrease
---

Analyze data coming from gauges. Unlike counters, gauges can decrease as well as increase.

If your value can only increase, use [`counter_agg`](/reference/toolkit/counters-and-gauges/counter_agg/index.md) instead to appropriately account for resets.

## Two-step aggregation

This group of functions uses the two-step aggregation pattern.

Rather than calculating the final result in one step, you first create an intermediate aggregate by using the aggregate function.

Then, use any of the accessors on the intermediate aggregate to calculate a final result. You can also roll up multiple intermediate aggregates with the rollup functions.

The two-step aggregation pattern has several advantages:

1. More efficient because multiple accessors can reuse the same aggregate
2. Easier to reason about performance, because aggregation is separate from final computation
3. Easier to understand when calculations can be rolled up into larger intervals, especially in window functions and continuous aggregates
4. Perform retrospective analysis even when underlying data is dropped, because the intermediate aggregate stores extra information not available in the final result

To learn more, see the [blog post on two-step aggregates](https://www.timescale.com/blog/how-postgresql-aggregation-works-and-how-it-inspired-our-hyperfunctions-design).

## Samples

### Analyze gauge metrics

Create hourly gauge aggregates and calculate changes:

```
SELECT
    time_bucket('1 hour'::interval, ts) AS hour,
    gauge_agg(ts, temperature) AS gauge_summary
FROM sensors
WHERE location = 'warehouse'
GROUP BY hour;
```

Calculate the delta and rate of change for gauge values:

```
WITH hourly AS (
    SELECT
        time_bucket('1 hour'::interval, ts) AS hour,
        gauge_agg(ts, temperature) AS gauge_summary
    FROM sensors
    WHERE location = 'warehouse'
    GROUP BY hour
)
SELECT
    hour,
    delta(gauge_summary) AS temp_change,
    rate(gauge_summary) AS temp_change_rate
FROM hourly
ORDER BY hour;
```

## Available functions

### Aggregate

- [`gauge_agg()`](/reference/toolkit/counters-and-gauges/gauge_agg/gauge_agg/index.md): aggregate gauge data into an intermediate form for further analysis

### Accessors

- [`corr()`](/reference/toolkit/counters-and-gauges/gauge_agg/corr/index.md): calculate the correlation coefficient from a gauge aggregate
- [`delta()`](/reference/toolkit/counters-and-gauges/gauge_agg/delta/index.md): calculate the change in a gauge’s value
- [`extrapolated_delta()`](/reference/toolkit/counters-and-gauges/gauge_agg/extrapolated_delta/index.md): estimate the total change in a gauge over a time period
- [`extrapolated_rate()`](/reference/toolkit/counters-and-gauges/gauge_agg/extrapolated_rate/index.md): estimate the average rate of change over a time period
- [`gauge_zero_time()`](/reference/toolkit/counters-and-gauges/gauge_agg/gauge_zero_time/index.md): calculate the time when a gauge value was zero
- [`idelta_left()`](/reference/toolkit/counters-and-gauges/gauge_agg/idelta_left/index.md): calculate the instantaneous change at the left boundary
- [`idelta_right()`](/reference/toolkit/counters-and-gauges/gauge_agg/idelta_right/index.md): calculate the instantaneous change at the right boundary
- [`intercept()`](/reference/toolkit/counters-and-gauges/gauge_agg/intercept/index.md): calculate the y-intercept from a gauge aggregate
- [`interpolated_delta()`](/reference/toolkit/counters-and-gauges/gauge_agg/interpolated_delta/index.md): calculate the change over a specific time range with interpolation
- [`interpolated_rate()`](/reference/toolkit/counters-and-gauges/gauge_agg/interpolated_rate/index.md): calculate the rate of change over a specific time range with interpolation
- [`irate_left()`](/reference/toolkit/counters-and-gauges/gauge_agg/irate_left/index.md): calculate the instantaneous rate at the left boundary
- [`irate_right()`](/reference/toolkit/counters-and-gauges/gauge_agg/irate_right/index.md): calculate the instantaneous rate at the right boundary
- [`num_changes()`](/reference/toolkit/counters-and-gauges/gauge_agg/num_changes/index.md): get the number of times the gauge changed value
- [`num_elements()`](/reference/toolkit/counters-and-gauges/gauge_agg/num_elements/index.md): get the number of points in a gauge aggregate
- [`rate()`](/reference/toolkit/counters-and-gauges/gauge_agg/rate/index.md): calculate the average rate of change
- [`slope()`](/reference/toolkit/counters-and-gauges/gauge_agg/slope/index.md): calculate the slope from a gauge aggregate
- [`time_delta()`](/reference/toolkit/counters-and-gauges/gauge_agg/time_delta/index.md): calculate the elapsed time in a gauge aggregate

### Rollup

- [`rollup()`](/reference/toolkit/counters-and-gauges/gauge_agg/rollup/index.md): combine multiple gauge aggregates

### Mutator

- [`with_bounds()`](/reference/toolkit/counters-and-gauges/gauge_agg/with_bounds/index.md): add time bounds to a gauge aggregate for extrapolation
