Return zero 0 when no data from flux query

I looked around, also in documentation but have not found how to overcome this…

Imaging when there no data to return because I am writing to database only when event occurs. Is there a way to make condition or return 0 when there is no data ?

I am presenting data from Grafana and I would rather display zero in some cases for users than no data.

Thanks

from(bucket: "test")
  |> range($range)
  |> filter(fn: (r) =>
    r._measurement == "quantity" and
    r._field == "countfld" and
    r.trigger == "reject")
|> drop(columns: ["msgid", "red", "green", "yellow", "trigger", "deviceid"])
|> sum(column: "_value")

@salvq There isn’t a way to do this, currently. fill() will replace null values with a specified value, but in your case, there aren’t any points with null values. There just aren’t any points so Flux doesn’t know what to fill.

What Flux is missing is time interpolation – the ability to create points at specific time intervals when no points exists. This is a known issue and there’s an issue/proposal on the Flux repo that outlines the problem and potential solutions: https://github.com/influxdata/flux/issues/436

This is what I was worry about :frowning: I will need to create some dummy records every x seconds in order to keep 0 as output.

Anyway, before your post I was about to try to utilize conditional approach within filter function, would this work to evaluate condition and if false create new table ? I have not deep dive that much in flux yet.

from(bucket: "test")
  |> range($range)
  |> filter(fn: (r) =>
    if r.trigger != "reject" then ....