InfluxQL query to Flux

Hi All!

I want to convert my old InfluxQL query to Flux and I`m stuck.
So, I have this query:

SELECT COUNT(my_field)
FROM
  (
    SELECT last(my_field) AS my_field
    FROM "my_table"
    WHERE $timeFilter
    GROUP BY time($__interval, -$time_influx_to_local), session_id fill(none)
  )
GROUP BY time($__interval, -$time_influx_to_local) fill(none)

I tried to do this but it has different results in comparison with my old approach

import "influxdata/influxdb/v1"

start_time = v.timeRangeStart
end_time = v.timeRangeStop

from(bucket: "my_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "my_table")
  |> filter(fn: (r) => r._field == "my_field")
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
  |> group()
  |> aggregateWindow(every: v.windowPeriod, fn: count, createEmpty: false)

Could someone help me?

Hello @masanoviv,
I don’t see the issue immediately. Your query looks good to me.
What are you getting and what are you expecting?