Select series whose maximum value less than 0

for example, there are like, 100 temperature series, I want to show series whose maximum temperature <= 0, ignore all other series. how can I do that?
There is what I got so for:

data=from(bucket: “telegraf/autogen”)
|> range(start: -7d)
|> filter(fn: (r) => r._measurement == “Temp” and r._field == “temp”)

|> group(columns: [“location”])
|> max()
|>filter(fn:(r)=> r._value<=0)

|> distinct(column: “location”)
|> keep(columns: [“_value”])

|> filter(fn:(r)=> contains(value: r.location, set: BelowZero))
|> yield()

I got the following error:
500 Internal Server Error: {“error”:“keyword argument "set" should be of kind array, but got object”}

How to fix that error?
I am new to Flux, I do not know what’s next. Thanks for your help in advance.


I tried to do something similar on some data that I had of 5 tanks (think of these as locations):

And here is the query to find the tanks whose maximum temperature is <= 50

from(bucket: "HyperEncabulator")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "TemperatureData")
  |> filter(fn: (r) => r["MeasType"] == "actual")
  |> filter(fn: (r) => r["Tank"] == "A5" or r["Tank"] == "B4" or r["Tank"] == "C3" or r["Tank"] == "D2" or r["Tank"] == "E1")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> max()
  |> filter(fn: (r) => r._value <= 50)
  |> keep(columns: ["Tank"])
  |> yield(name: "last")

Thank you for your help.
find out the tanks whose temp<=50 is the first step. the requirement is to show temperature series of these tanks, in your example, only show temperature line of A5,D2 and E1, not all five of them in your first chart.
Thanks again.

Hello @AlpGlide,
If you look at the graph above only 3 series (A5 D2 and E1) are below 50 so he’s sowing the temperature series of those tanks below 50.

Can you help me understand what you mean a little better?
Also I noticed in your script that you have a capital Data instead of data.

I may be jumping in here, but I believe that @AlpGlide wants to see only the three lines on the graph that have a max temp <= 50. My query displays the 3 series that “pass the test”, but in separate tables. I think the goal is to have ONLY those series display on the chart / graph entirely. And that is where I got stuck as well.

yes, “the goal is to have ONLY those series display on the chart / graph entirely” . The basic requirement from operation group is " we only want to see the time series that we concern, not others"
We know how to find out these three tanks whose temp <=50, the requirement is to show only these series, while ignore other series. The key is how to use the result in the new queries(in grant1’s exmaple):
If I use something like this
|> filter(fn:(r)=> contains(value: r.Tank, set: TanksBelow50))
The error says TanksBelow50 is not array. of course, it’s table result, not array. how to turn result table to array?
Thanks for your help.

yes, you are right. “Data” should be data. Sorry for that.

my workaround is to set TanksBelow50 result as a Grafana variable, it will automatically turn the result to an array, then |> filter(fn:(r)=> contains(value: r.Tank, set: ${TanksBelow50})) works, the time series chart only show 3 series (A2,D2 and E1).
but this is the only work around, I want to know how to implement in Flux query, not depends on others(like grafana dashboard variables) to help.
Thank you for your help.