Hour selection not working with grafana

I have a production data and I am trying to filter the data based on time because I need data for each shift. I have written my query as below:

import "experimental/date/boundaries"
thisWeek = boundaries.week(start_sunday: true,)

from(bucket: "production")
  |> range(start: thisWeek.start, stop: thisWeek.stop)
  |> filter(fn: (r) => r._measurement == "productioncounters" and r._field == "counter" and r.line == "2L")
  |> aggregateWindow(every: 5m, fn: last, createEmpty: false)
  |> max()
  |> group()
  |> keep(columns:["_time", "_value", "sap"])
  |> sort(columns: ["_time"])

This gives me the table

When I add hour selection in the query as below

import "experimental/date/boundaries"
thisWeek = boundaries.week(start_sunday: true,)

from(bucket: "production")
  |> range(start: thisWeek.start, stop: thisWeek.stop)
  |> filter(fn: (r) => r._measurement == "productioncounters" and r._field == "counter" and r.line == "2L")
  |> aggregateWindow(every: 5m, fn: last, createEmpty: false)
  |> max()
  |> group()
  |> keep(columns:["_time", "_value", "sap"])
  |> sort(columns: ["_time"])
  |> hourSelection(start: 7, stop: 15, timeColumn: "_time")

The output is

This is not working as I expected, What I want is for each sap during that particular shift( the slected hours), I need the maximum value and add them to find the total produced units during that shift . can someone help me with this.

Hello @tejaswy,
I’m sorry I’m a little confused why hourSelection isn’t giving you the values you expect. It looks like its correctly filtering out and rows with a _time <= 7th hour or _time >= 15th hour.

Could you maybe share your expected output numerically?

Hi @Anaisdg , The query works for me when i use the values as 6 and 13 instead of 7 and 15? Do you have any idea why this could be?

That’s strange. I’m not experiencing that issue. Sorry if this is a silly question, but are you sure it’s not an issue of inequalities? > vs >=
Otherwise you can submit an issue here:

@Anaisdg I was just going through this again . I couldn’t understand this: <= 7th hour or _time >= 15th hour. Numerically what I would want is all field values which occur during the period 7:00 to 15:00 . If this clarifies?