Aggregation per hour - only want to display full hour

Hi Community, I am using the below code:

from(bucket: "fabian")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Sensoren")
  |> filter(fn: (r) => r["_field"] == "Temperature")
  |> filter(fn: (r) => r["Sensor-ID"] =~ /^${Sensor:regex}$/)
  |> aggregateWindow(every: 1h, fn: max, createEmpty: false)
  |> yield(name: "max")

Outcome looks like this:

The top entry is changing constantly with Dashboard refresh Iw ould like to see only full hours? how to achieve?

Hi @github-ps1304

This should eliminate the current hour:

import "date"

endHour = date.truncate(t: -1h, unit: 1h)

from(bucket: "fabian")
|> range(start: -3h, stop: endHour)

Thanks @grant1 will give it a try. Does it work with other periods as well eg: week , month etc.?

Yes, it should work with other time periods.

If the data is large, do we need to add months and hours as tags to speed up query time?