InfluxDB Docs

filter() function

The filter() function filters data based on conditions defined in a predicate function (fn). The output tables have the same schema as the corresponding input tables.

Function type: Transformation
Output data type: Object

filter(fn: (r) => r._measurement == "cpu")

Parameters

Make sure fn parameter names match each specified parameter. To learn why, see Match parameter names.

fn

A single argument predicate function that evaluates true or false. Records are passed to the function. Those that evaluate to true are included in the output tables. Records that evaluate to null or false are not included in the output tables.

Data type: Function

Objects evaluated in fn functions are represented by r, short for “record” or “row”.

Examples

Filter based on measurement, field, and tag
from(bucket:"example-bucket")
  |> range(start:-1h)
  |> filter(fn: (r) =>
    r._measurement == "cpu" and
    r._field == "usage_system" and
    r.cpu == "cpu-total"
  )
Filter out null values
from(bucket:"example-bucket")
  |> range(start:-1h)
  |> filter(fn: (r) => exists r._value )
Filter values based on thresholds
from(bucket:"example-bucket")
  |> range(start:-1h)
  |> filter(fn: (r) => r._value > 50.0 and r._value < 65.0 )

SELECT