---
title: aggregate.rate() function
description: aggregate.rate() calculates the average rate of increase per window of time for each input table.
url: https://docs.influxdata.com/flux/v0/stdlib/experimental/aggregate/rate/
estimated_tokens: 1369
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/experimental/aggregate/rate/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.61.0+

InfluxDB support

> [!Important]
> `aggregate.rate()` is experimental and [subject to change at any time](/flux/v0/stdlib/experimental/#experimental-packages-are-subject-to-change).

`aggregate.rate()` calculates the average rate of increase per window of time for each
input table.

`aggregate.rate()` requires that input data have `_start` and `_stop` columns
to calculate windows of time to operate on.
Use `range()` to assign `_start` and `_stop` values.

This function is designed to replicate the[Prometheus `rate()` function](https://prometheus.io/docs/prometheus/latest/querying/functions/#rate)and should only be used with [counters](/flux/v0/prometheus/metric-types/counter/).

##### Function type signature

```js
(<-tables: stream[A], every: duration, ?groupColumns: [string], ?unit: duration) => stream[B] where A: Record, B: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### every

(Required)
Duration of time windows.

### groupColumns

List of columns to group by. Default is `[]`.

### unit

Time duration to use when calculating the rate. Default is `1s`.

### tables

Input data. Default is piped-forward data (`<-`).

## Examples

### Calculate the average rate of change in data

```js
import "experimental/aggregate"
import "sampledata"

data =
    sampledata.int()
        |> range(start: sampledata.start, stop: sampledata.stop)

data
    |> aggregate.rate(every: 30s, unit: 1s, groupColumns: ["tag"])
```

[](#view-example-input-and-output)

View example input and output

#### Input data

|     \*\_start      |      \*\_stop      |       \_time       |\_value|\*tag|
|--------------------|--------------------|--------------------|-------|-----|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:00Z|  \-2  | t1  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:10Z|  10   | t1  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:20Z|   7   | t1  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:30Z|  17   | t1  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:40Z|  15   | t1  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:50Z|   4   | t1  |

|     \*\_start      |      \*\_stop      |       \_time       |\_value|\*tag|
|--------------------|--------------------|--------------------|-------|-----|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:00Z|  19   | t2  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:10Z|   4   | t2  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:20Z|  \-3  | t2  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:30Z|  19   | t2  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:40Z|  13   | t2  |
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|2021-01-01T00:00:50Z|   1   | t2  |

#### Output data

|     \*\_start      |      \*\_stop      |\*tag|\_value|       \_time       |
|--------------------|--------------------|-----|-------|--------------------|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z| t1  |  1.2  |2021-01-01T00:00:30Z|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z| t1  |   1   |2021-01-01T00:01:00Z|

|     \*\_start      |      \*\_stop      |\*tag|\_value|       \_time       |
|--------------------|--------------------|-----|-------|--------------------|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z| t2  |       |2021-01-01T00:00:30Z|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z| t2  |  2.2  |2021-01-01T00:01:00Z|

#### Related

* [Calculate the rate of change](/influxdb/v2/query-data/flux/rate/)

[transformations](/flux/v0/tags/transformations/)[aggregates](/flux/v0/tags/aggregates/)
| *_start | *_stop | _time | _value | *tag |
| --- | --- | --- | --- | --- |
| *_start | *_stop | _time | _value | *tag |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |

| *_start | *_stop | _time | _value | *tag |
| --- | --- | --- | --- | --- |
| *_start | *_stop | _time | _value | *tag |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |

| *_start | *_stop | *tag | _value | _time |
| --- | --- | --- | --- | --- |
| *_start | *_stop | *tag | _value | _time |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | t1 | 1.2 | 2021-01-01T00:00:30Z |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | t1 | 1 | 2021-01-01T00:01:00Z |

| *_start | *_stop | *tag | _value | _time |
| --- | --- | --- | --- | --- |
| *_start | *_stop | *tag | _value | _time |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | t2 |  | 2021-01-01T00:00:30Z |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | t2 | 2.2 | 2021-01-01T00:01:00Z |
