Documentation

Calculate the rate of change

This page documents an earlier version of InfluxDB. InfluxDB v1.8 is the latest stable version. View this page in the v1.8 documentation.

See the equivalent InfluxDB v2.0 documentation: Calculate the rate of change.

Use the derivative() function to calculate the rate of change between subsequent values or the aggregate.rate() function to calculate the average rate of change per window of time. If time between points varies, these functions normalize points to a common time interval making values easily comparable.

Rate of change between subsequent values

Use the derivative() function to calculate the rate of change per unit of time between subsequent non-null values.

data
  |> derivative(unit: 1s)

By default, derivative() returns only positive derivative values and replaces negative values with null. Cacluated values are returned as floats.

Given the following input:

_time_value
2020-01-01T00:00:00Z250
2020-01-01T00:04:00Z160
2020-01-01T00:12:00Z150
2020-01-01T00:19:00Z220
2020-01-01T00:32:00Z200
2020-01-01T00:51:00Z290
2020-01-01T01:00:00Z340

derivative(unit: 1m) returns:

_time_value
2020-01-01T00:04:00Z
2020-01-01T00:12:00Z
2020-01-01T00:19:00Z10.0
2020-01-01T00:32:00Z
2020-01-01T00:51:00Z4.74
2020-01-01T01:00:00Z5.56

Results represent the rate of change per minute between subsequent values with negative values set to null.

Return negative derivative values

To return negative derivative values, set the nonNegative parameter to false,

Given the following input:

_time_value
2020-01-01T00:00:00Z250
2020-01-01T00:04:00Z160
2020-01-01T00:12:00Z150
2020-01-01T00:19:00Z220
2020-01-01T00:32:00Z200
2020-01-01T00:51:00Z290
2020-01-01T01:00:00Z340

The following returns:

|> derivative(
  unit: 1m,
  nonNegative: false
)
_time_value
2020-01-01T00:04:00Z-22.5
2020-01-01T00:12:00Z-1.25
2020-01-01T00:19:00Z10.0
2020-01-01T00:32:00Z-1.54
2020-01-01T00:51:00Z4.74
2020-01-01T01:00:00Z5.56

Results represent the rate of change per minute between subsequent values and include negative values.


New! Cloud or OSS?