# Fill() does not fill previous

**URL:** <https://community.influxdata.com/t/fill-does-not-fill-previous/35142>\
**Category:** InfluxDB 2\
**Tags:** flux\
**Created:** [August 1, 2024, 2:12am UTC](https://community.influxdata.com/t/fill-does-not-fill-previous/35142 "2024-08-01T02:12:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@Leo](https://community.influxdata.com/u/Leo)\
**Post date:** [August 1, 2024, 2:12am UTC](https://community.influxdata.com/t/fill-does-not-fill-previous/35142/1 "2024-08-01T02:12:16Z")

</div>

Hello:  
When i use fill(usePrevious: true) to fill null, i found a piece of data filled not from previous.

1. when none fill, the lastest is 26.4 at 2024-07-31 13:36:29, the rest is null  

2. when filled, the last is 26.3 at 2024-07-31 13:41:27, which should be 26.4  

so I dont know where 26.3 come from, how can i do to get the right fill

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 1, 2024, 7:48pm UTC](https://community.influxdata.com/t/fill-does-not-fill-previous/35142/2 "2024-08-01T19:48:44Z")

</div>

Hello @Leo,  
That is truly odd. I did see this issue:

> <https://github.com/influxdata/flux/issues/3521>
>
> The \`fill()\` function exists to replace null values with a given value; however,… depending on your source data and the way stuff is grouped, in some tables you may end up with the column being entirely absent, in which case \`fill()\` throws an error. In order to get reliable behavior, you end up having to use \`map(fn: (r) =\> r with my\_column: if exists r.my\_column then r.my\_column else "foo"}))\`, which is \_logically\_ the same as \`fill(column: "my\_column", value: "foo")\`, but works even if \`my\_column\` happens to be absent entirely for a given table.
> 
> As an example of a real query where this becomes an issue, here is a query I wrote as part of a check that would look for (and alert on) task failures:
> 
> \`\`\`flux
> from(bucket: "\_tasks")
> |\> range(start: -10m)
> |\> schema.fieldsAsCols()
> |\> group(columns: \["taskID"\])
> |\> fill(column: "errorMessage", value: "(none)")
> |\> monitor.check(
> crit: (r) =\> r.status == "failed",
> messageFn: (r) =\> (
> if r.status == "failed" then "Task '${r.name}' failed! Error message: ${r.errorMessage}"
> else "Task '${r.name}' succeeded."
> ),
> data: {...},
> )
> \`\`\`
> 
> This looks perfectly fine at first glance, but when the check is executed, if any of the tasks had no errors in the past ten minutes, then the table for that task will have no \`errorMessage\` column, and then \`fill()\` will fail with \`fill column not found: errorMessage\`.

I wonder if it’s related. Maybe try commenting there?

---

<div class="post-metadata">

**Author:** ![Leo](https://avatars.discourse-cdn.com/v4/letter/l/c2a13f/32.png) [@Leo](https://community.influxdata.com/u/Leo)\
**Post date:** [August 5, 2024, 2:15am UTC](https://community.influxdata.com/t/fill-does-not-fill-previous/35142/3 "2024-08-05T02:15:08Z")

</div>

thanks for your reply.  
but the column need to be filled with previous value rather than a fixed value. Is there any better way?

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 6, 2024, 9:46pm UTC](https://community.influxdata.com/t/fill-does-not-fill-previous/35142/4 "2024-08-06T21:46:35Z")

</div>

Hello @Leo,  
I recommend creating an issue for that. The function should fill previous easily.  
I’m not able to reproduce. Is there anyway you can limit your data to 4 lines where its not filling properly? and then export to annotated csv and share here? That way I can see the group keys and maybe try and figure out what the heck is happening.
