---
title: Fill null values in data
description: Use fill() function to replace null values.
url: https://docs.influxdata.com/influxdb/v2/query-data/flux/fill/
estimated_tokens: 922
product: InfluxDB OSS v2
version: v2
publisher: InfluxData
canonical: https://docs.influxdata.com/influxdb/v2/query-data/flux/fill/
date: '2025-04-02T15:54:32-06:00'
lastmod: '2025-04-02T15:54:32-06:00'
---

This page documents an earlier version of InfluxDB OSS.[InfluxDB 3 Core](/influxdb3/core/) is the latest stable version.

#### API token hashing is enabled by default in InfluxDB OSS 2.9.0

Stronger token security: tokens are stored as hashes on disk, so a
copy of the database file doesn’t expose usable tokens. Existing
tokens are hashed on first startup and the original strings can’t
be recovered afterward — **capture any plaintext tokens you still
need before you upgrade**.

For more information, see [Token hashing](/influxdb/v2/admin/tokens/#token-hashing).

Use [`fill()`](/flux/v0/stdlib/universe/fill/)to replace *null* values with:

* [the previous non-null value](#fill-with-the-previous-value)
* [a specified value](#fill-with-a-specified-value)

```js
data
    |> fill(usePrevious: true)

// OR

data
    |> fill(value: 0.0)
```

#### 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](https://github.com/influxdata/flux/issues/2428))*.

## 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.

```js
data
    |> fill(usePrevious: true)
```

**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  |

**`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  |

## 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](/flux/v0/spec/types/#basic-types)of the [column](/flux/v0/stdlib/universe/fill/#column).*

```js
data
    |> fill(value: 0.0)
```

**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  |

**`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  |

#### Related

* [fill() function](/flux/v0/stdlib/universe/fill/)

[query](/influxdb/v2/tags/query/)[fill](/influxdb/v2/tags/fill/)
| _time | _value |
| --- | --- |
| _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 |

| _time | _value |
| --- | --- |
| _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 |

| _time | _value |
| --- | --- |
| _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 |

| _time | _value |
| --- | --- |
| _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 |
