Only retrieve field key name that have a valid value

Hello,

I have several queries working together to create a UI, one query gets the Field keys so that a user can select which one they want. The problem is that the user will select a field key that hasn’t had recent data and will throw an error.

This could be solved by only showing the field keys for a specific time interval. Is this possible, or am I over thinking it?

Any advice would be greatly appreciated,

Cheers

Hello @GannanTech,
Welcome! I believe you’re missing a map. The following worked for me.

from(bucket: "default")
  |> range(start: -30d)
  |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_user" and r.cpu == "cpu-total")
  |> count()
  |>  map(fn: (r) => ({
        r with hour: 
        if r._value >= 60 then r._value / 60 
        else if r._value >= 3600 then r._value / 3600 
        else r._value
        }))