Flux query problem

I collect data with telegraf.inputs.opcua.listener.
I collect only boolean data.
I create visualisation in grafana (industrial signals) and
I Have problem. I have in the same time two signals with value==true.
I would like set prority on one with their.
How to create flux query where I will have set prority on one of two value true but when only one is true or two false all works fine

Hello @Michu123 ,
I’m having trouble understanding your question.
Can you please try to explain again?

Are you using Flux to query? Or InfluxQL? What version of InfluxDB are you using?

If you’re using Flux, maybe you want conditional filtering?

Hi @Michu123

Assuming your two signals have different _field values (e.g., signal1 and signal2 ), perhaps something like this?

from(bucket: "your_bucket_name")
  |> range(start: -7d) // Adjust the range as needed
  |> filter(fn: (r) => r["_measurement"] == "your_measurement_name")
  |> filter(fn: (r) => r["_field"] == "signal1" or r["_field"] == "signal2")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> filter(fn: (r) => r.signal1 != r.signal2)

In the above query, I first filter the data based on the measurement and field names. Then, I use the pivot() function to create one column for each signal. Finally, I use the filter() function to keep only the rows where the values of signal1 and signal2 are different, which means either only one of them is true or both are false.

If you want to keep the rows where both signals are false, you can simply modify the filter function in the previous query, like this:

from(bucket: "your_bucket_name")
  |> range(start: -7d) // Adjust the range as needed
  |> filter(fn: (r) => r["_measurement"] == "your_measurement_name")
  |> filter(fn: (r) => r["_field"] == "signal1" or r["_field"] == "signal2")
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> filter(fn: (r) => r.signal1 == false and r.signal2 == false)