Help with Flux Query versus Transformation in Grafana

Hi all, still learning flux but don’t know how to achieve what I’m looking for.

This is our base query:

from(bucket: “rt-data”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “site”)
|> filter(fn: (r) => r[“point_name”] == “TotalRack_Online”)
|> group(columns: [“_measurement”], mode:“by”)
|> pivot(rowKey:[“_time”], columnKey: [“point_name”], valueColumn: “_value”)
|> rename(columns: {TotalRack_Online: “_value”})
|> aggregateWindow(every: 1h , fn: mean)

I need the _value column to actually represent “TotalRack_Online” / 42. How do I add this transformation into my Flux Query? Right now, I do the division in Grafana. Please help!

Thanks so much.

I tried this and seems to work? Is this an ok way to do what I need?

from(bucket: “rt-data”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “site”)
|> filter(fn: (r) => r[“point_name”] == “TotalRack_Online”)
|> aggregateWindow(every: 1d , fn: mean)
|> map(fn: (r) => ({
_time: r._time,
_point_name: “TotalRack_Online”,
_value: r._value / 42.0,
}),
)

Hello @Marion_Akagi
That’s absolutely correct.
however you can simplify your map to just transform the _value if you want. Up to you :slight_smile:

1 Like