Count the number of time Series with a specific value

Hey,

i have 20 machines which produce a time Series each with the current state of the machine. Each time series looks similiar to this:

The integer Numbers represent the state like filling, pumping or error.
What i want to know is how many of my machines are in a specific state at any given time and show this information in the graph panel.
So with 20 machines i expect something like 14 are in the state 1;16 or 32
and 6 machines are in the other states.

Is this somehow possible?

Thank you for your help in advance.

Hello @Patse,
Absolutely.
With flux it would look something like:

from(bucket: "myData")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "myMeasurement")
  |> filter(fn: (r) => r["_field"] == "opcua.value_int")
  |> group(columns: ["_value"], mode:"by")
  |> count() 
  |> yield(name: "like states")

Somhow this isn’t working for me. I think this is becaus of how me raw data is structured.
I have one field for each possible data type like value_int or value_str.
All the data from the machines is written into these fields and it doesn’t matter which machine it is or from which sensor the data originates. To distinguish between the different sensors and machines i have a tag called “short” which has all the Information for this data point like Machine1_status. So all data points which belong to machine1 and are the status get the the tag “Machine1_status”

And i have this “short” for each machine. How do i have to change the Query?
I tried to implement a new line with

|> filter(fn: (r) => r[“short”] == “machine1_status” or
r[“short”] == “machine2_status”
)

but then i get the error
image

My whole Query was the following

from(bucket: “my bucket”)

|> range(start: 2021-01-01T00:00:00Z)

|> filter(fn: (r) => r["_measurement"] == “myMeasurement”)

|> filter(fn: (r) => r["_field"] == “value_int”)

|> filter(fn: (r) => r[“short”] == “Machine1_status” or

                r["short"] == "Machine2_status"

)

|> group(columns: ["_value"], mode:“by”)

|> count()

|> yield(name: “like states”)

Thank you so much for your help in advance