docs-v2/content/influxdb/v2.1/query-data/flux/fill.md

2.8 KiB

title seotitle list_title description weight menu influxdb/v2.1/tags related list_query_example
Fill null values in data Fill null values in data Fill Use `fill()` function to replace _null_ values. 210
influxdb_2_1
parent name
Query with Flux Fill
query
fill
/{{< latest "flux" >}}/stdlib/universe/fill/
fill_null

Use [fill()](/{{< latest "flux" >}}/stdlib/universe/fill/) to replace null values with:

data
    |> fill(usePrevious: true)

// OR

data
    |> fill(value: 0.0)

{{% note %}}

Fill empty windows of time

The fill() function does not fill empty windows of time. It only replaces null values in existing data. Filling empty windows of time requires time interpolation (see influxdata/flux#2428). {{% /note %}}

Fill with the previous value

To fill null values with the previous non-null value, set the usePrevious parameter to true.

{{% note %}} Values remain null if there is no previous non-null value in the table. {{% /note %}}

data
    |> fill(usePrevious: true)

{{< flex >}} {{% flex-content %}} Given the following input:

_time _value
2020-01-01T00:01:00Z null
2020-01-01T00:02:00Z 0.8
2020-01-01T00:03:00Z null
2020-01-01T00:04:00Z null
2020-01-01T00:05:00Z 1.4
{{% /flex-content %}}
{{% flex-content %}}
fill(usePrevious: true) returns:
_time _value
2020-01-01T00:01:00Z null
2020-01-01T00:02:00Z 0.8
2020-01-01T00:03:00Z 0.8
2020-01-01T00:04:00Z 0.8
2020-01-01T00:05:00Z 1.4
{{% /flex-content %}}
{{< /flex >}}

Fill with a specified value

To fill null values with a specified value, use the value parameter to specify the fill value. The fill value must match the [data type](/{{< latest "flux" >}}/spec/types/#basic-types) of the [column](/{{< latest "flux" >}}/stdlib/universe/fill/#column).

data
    |> fill(value: 0.0)

{{< flex >}} {{% flex-content %}} Given the following input:

_time _value
2020-01-01T00:01:00Z null
2020-01-01T00:02:00Z 0.8
2020-01-01T00:03:00Z null
2020-01-01T00:04:00Z null
2020-01-01T00:05:00Z 1.4
{{% /flex-content %}}
{{% flex-content %}}
fill(value: 0.0) returns:
_time _value
2020-01-01T00:01:00Z 0.0
2020-01-01T00:02:00Z 0.8
2020-01-01T00:03:00Z 0.0
2020-01-01T00:04:00Z 0.0
2020-01-01T00:05:00Z 1.4
{{% /flex-content %}}
{{< /flex >}}