Struggling with query from 1.8 to v2 in Grafana

How do i query :

SELECT spread(“Value”) FROM “471200_STEM_AHU01” WHERE (“Units” = ‘kWh’ AND “Name” = ‘AV_1002_STEM_AHU01_SF1_ELEC_CONS_KWH_AV’) AND time >= now() - 24h GROUP BY time(1h), “Name”

from influx 1.8 in v2. I can’t get the value to spread every 1h. Can’t figure out how to make the GROUP BY time(1h) function in v2.

So far, this is what i ended up with:

from(bucket: “048_STEM”)

|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “471200_STEM_AHU01”)
|> filter(fn: (r) => r[“Units”] == “kWh”)
|> filter(fn: (r) => r[“Name”] == “AV_1002_STEM_AHU01_SF1_ELEC_CONS_KWH_AV”)
|> filter(fn: (r) => r["_field"] == “Value”)
|> spread()

Thx in advance!

@bmenard This should get you what you need:

from(bucket: "example-bucket")
  |> range(start: -24h)
  |> filter(fn: (r) =>
    r._measurement == "471200_STEM_AHU01" and
    r._field == "Value" and
    r.Units == "kWh" and
    r.Name == "AV_1002_STEM_AHU01_SF1_ELEC_CONS_KWH_AV"
  |> aggregateWindow(every: 1h, fn: spread)
1 Like

Thx! You made my weekend!

Man do i love Influxdb and his community!

Have a good weekend my friend!

Happy to help! Have a great weekend!