Count occurance of tags in measurment

Hi all!

I have a measurement where I store measurement values from multiple sensors (differentiated by sensor ID).

meter_readings,sensor_ID=Sensor_01 sensor_reading=1589 1617451200000
meter_readings,sensor_ID=Sensor_02 sensor_reading=1700 1617444000000
meter_readings,sensor_ID=Sensor_08 sensor_reading=700 1617442000000

Now I want to display in grafanas bar gauge how many measurment values I got per sensor (in decreasing order). e.g.

Sensor_03 ||||||||||||||||||||||||||||||||||
Sensor_01 ||||||||||||||||||||||||||
Sensor_02 ||||||||

The closest I get to this is to display the number of measurment values per sensor in alphabetical Order. e.g.

Sensor_01 ||||||||||||||||||||||||||
Sensor_02 ||||||||
Sensor_03 ||||||||||||||||||||||||||||||||||

I can achieve this by the following flux query:

from(bucket: “admin-bucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “meter_readings” )
|> filter(fn: (r) => r["_field"] == “sensor_reading”)
|> count()

this gives me x table where x is the number of sensor available in the measurement.
However I could not find a solution how to combine the individual tables like this:

sensor_ID | count

Sensor_01 | 8
Sensor_02 | 4
Sensor_03 | 10

or to bring the individual tables that I already got in some order different than alphabetical order.
Can you please help me?

Thanks,

Andreas

Ok, I think I found the solution. This query did the trick:
from(bucket: “admin-bucket”)

|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “missing_meter_readings” )
|> keep(columns: [“sensor_ID”,"_value"])
|> count()
|> group()
|> sort()

however my barchart now looks like this:

_value |||
_value |||||||||||
_value ||||||||||||||

so instead of displaying the sensor_ID it just displays _value as label for each bar

Hello @Andreas_E,
That’s a little odd.
Does specifying the column help at all?

 |> sort(columns: ["sensor_ID"], desc: false)