Documentation

movingAverage() function

Flux 0.35.0+

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

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

(Required) The number of points to average.

tables

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

Examples

The following examples use data provided by the sampledata package to show how movingAverage() transforms data.

Calculate a three point moving average

import "sampledata"

sampledata.int()
  |> movingAverage(n: 3)

View input and output

Calculate a three point moving average with null values

import "sampledata"

sampledata.int(includeNull: true)
  |> movingAverage(n: 3)

View input and output


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.