I have this Bar Gauge Panel with override field. I want them to be in the order which is SOC<100%, SOC<75%, SOC<50%, SOC<25%. Is it possible to achieve this in Grafana or is there a alternative way to achieve this? I’m using flux query language and I have ordered them in the order I mentioned above in the map function. Also, I have tried with transform sort by value and it doesn’t work.
Welcome @linpyae95
Please share your current Flux query
import "join"
allMpptStats =
from(bucket: "pbms")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mpptstats")
|> last()
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> group()
allSOC =
from(bucket: "pbms")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "soc_estimation")
|> last()
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> group()
allRec =
join.left(
left: allMpptStats,
right: allSOC,
on: (l, r) => l.mac == r.mac,
as: (l, r) =>
({
mac: l.mac,
vendor: l.vendor,
site: l.site,
site_type: l.site_type,
is_discharge: l.is_discharge,
soc: if l.vendor == "Hanfsolar" then r.soc else l.soc,
controller_number: l.controller_number,
}),
)
|> group()
|> filter(fn: (r) => r.controller_number != "unknown")
|> unique(column: "mac")
|> map(
fn: (r) => ({ r with soc_by_range: if r.soc >=75 and r.soc <= 100 then "SOC < 100%"
else if r.soc >= 50 and r.soc <= 74 then "SOC < 75%"
else if r.soc >=25 and r.soc <=49 then "SOC < 50%"
else "SOC < 25%"
}))
|> yield(name: "result")
1 Like
You have mapped them but not ordered them I don’t think.
Might want to assign a numeric value to them and order by that static numeric value
sort()
Also post this question in the influx data forum
thanks. That’s work @yosiasz
Please share what works