---
title: timedMovingAverage() function
description: timedMovingAverage() returns the mean of values in a defined time range at a specified frequency.
url: https://docs.influxdata.com/flux/v0/stdlib/universe/timedmovingaverage/
estimated_tokens: 1278
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/universe/timedmovingaverage/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.36.0+

InfluxDB support

`timedMovingAverage()` returns the mean of values in a defined time range at a
specified frequency.

For each row in a table, `timedMovingAverage()` returns the average of the
current value and all row values in the previous `period` (duration).
It returns moving averages at a frequency defined by the `every` parameter.

#### Aggregate by calendar months and years

`every` and `period` parameters support all valid duration units, including
calendar months (`1mo`) and years (`1y`).

#### Aggregate by week

When aggregating by week (`1w`), weeks are determined using the Unix epoch
(1970-01-01T00:00:00Z UTC). The Unix epoch was on a Thursday, so all
calculated weeks begin on Thursday.

##### Function type signature

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

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

## Parameters

### every

(Required)
Frequency of time window.

### period

(Required)
Length of each averaged time window.

A negative duration indicates start and stop boundaries are reversed.

### column

Column to operate on. Default is `_value`.

### tables

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

## Examples

### Calculate a five year moving average every year

```js
data
    |> timedMovingAverage(every: 1y, period: 5y)
```

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

View example input and output

#### Input data

|     \*\_start      |      \*\_stop      |       \_time       |\_value|
|--------------------|--------------------|--------------------|-------|
|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|2015-01-01T00:00:00Z|   0   |
|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|2016-01-01T08:00:00Z|   1   |
|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|2016-12-31T16:00:00Z|   4   |
|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|2018-01-01T00:00:00Z|   9   |
|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|2019-01-01T08:00:00Z|  16   |
|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|2020-01-01T16:00:00Z|  25   |

#### Output data

|       \_time       |     \*\_start      |      \*\_stop      |     \_value      |
|--------------------|--------------------|--------------------|------------------|
|2016-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|        0         |
|2017-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|1.6666666666666667|
|2018-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|1.6666666666666667|
|2019-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|       3.5        |
|2020-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|        6         |
|2021-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|        11        |
|2021-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|16.666666666666668|
|2021-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|16.666666666666668|
|2021-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|       20.5       |
|2021-01-01T00:00:00Z|2015-01-01T00:00:00Z|2021-01-01T00:00:00Z|        25        |

#### Related

* [movingAverage() function](/flux/v0/stdlib/universe/movingaverage/)
* [exponentialMovingAverage() function](/flux/v0/stdlib/universe/exponentialmovingaverage/)
* [doubleEMA() function](/flux/v0/stdlib/universe/doubleema/)
* [tripleEMA() function](/flux/v0/stdlib/universe/tripleema/)
* [Calculate the moving average](/influxdb/v2/query-data/flux/moving-average/)
* [InfluxQL MOVING\_AVERAGE()](/influxdb/v1/query_language/functions/#moving-average)

[transformations](/flux/v0/tags/transformations/)
| *_start | *_stop | _time | _value |
| --- | --- | --- | --- |
| *_start | *_stop | _time | _value |
| 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 0 |
| 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 2016-01-01T08:00:00Z | 1 |
| 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 2016-12-31T16:00:00Z | 4 |
| 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 2018-01-01T00:00:00Z | 9 |
| 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 2019-01-01T08:00:00Z | 16 |
| 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 2020-01-01T16:00:00Z | 25 |

| _time | *_start | *_stop | _value |
| --- | --- | --- | --- |
| _time | *_start | *_stop | _value |
| 2016-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 0 |
| 2017-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 1.6666666666666667 |
| 2018-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 1.6666666666666667 |
| 2019-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 3.5 |
| 2020-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 6 |
| 2021-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 11 |
| 2021-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 16.666666666666668 |
| 2021-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 16.666666666666668 |
| 2021-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 20.5 |
| 2021-01-01T00:00:00Z | 2015-01-01T00:00:00Z | 2021-01-01T00:00:00Z | 25 |
