Documentation

timeWeightedAvg() function

The timeWeightedAvg() function outputs the time-weighted average of non-null records in a table as a float. Time is weighted using the linearly interpolated integral of values in the table. timeWeightedAvg() is an aggregate function.

Output data type: Float

timeWeightedAvg(unit: 1m)

Parameters

unit

(Required) Time duration used when computing the time-weighted average.

tables

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

Examples

The following example uses data provided by the sampledata package to show how timeWeightedAvg() transforms data.

import "sampledata"

data = sampledata.int(includeNull: true)
    |> range(start: sampledata.start, stop: sampledata.stop)
    |> fill(usePrevious: true)
    |> unique()

data
    |> timeWeightedAvg(unit: 1s)

View input and output


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.