movingAverage() function

The movingAverage() function calculates the mean of values in the _values column grouped into n number of points.

*Function type: Transformation*

  1. movingAverage(n: 5)
Moving average rules
  • The average over a period populated by n values is equal to their algebraic mean.
  • The average over a period populated by only null values is null.
  • Moving averages skip null values.
  • If n is less than the number of records in a table, movingAverage returns the average of the available values.

Parameters

n

The number of points to average.

*Data type: Integer*

Examples

Calculate a five point moving average

  1. from(bucket: "example-bucket"):
  2. |> range(start: -12h)
  3. |> movingAverage(n: 5)

Table transformation with a two point moving average

Input table:
_timetag_value
0001tvnull
0002tv6
0003tv4
Query:
  1. // ...
  2. |> movingAverage(n: 2 )
Output table:
_timetag_value
0002tv6
0003tv5

Related articles