0 instead of "No Data", "else" not working as expected

Hello @cholzer,
The issue is that if you aren’t returning data after the range, filter, or agg window functions then you have nothing to map to.
What you can do is create an array something like:

import "array"
import "experimental"

// Query data from the bucket
noResultData = from(bucket: "anais")
  |> range(start: -1d)
  |> map(fn: (r) => ({
        r with
        _value: float(v: r._value) + 100.0
      })
    )

// Fallback data
whenNo = array.from(rows: [{_measurement: "test", _time: 2020-01-01T00:00:00Z, _field: "test", _value: 0.0}])

// Attempt to merge the query result with fallback data, ensuring at least one record is present
dataExists = exists (noResultData |> findRecord(fn: (key) => true, idx: 0))._value

if dataExists 
then noResultData |> yield(name: "data")
else whenNo 

heres another approach:

1 Like