Using the following query
SELECT FLOOR(__time to HOUR) AS HourTime, latest("value", 20), max(__time)
FROM "Telegraf"
WHERE source = 'switch1' AND resource = 'Ethernet17' AND
metric_group = 'ifcounters' AND metric = 'in_octets' AND
TIME_IN_INTERVAL("__time", '2023-05-01/2023-05-05')
GROUP BY 1
Which gives me output like the below. Note the datapoints are not exactly on the time boundary and there could be gaps too in the series.
What I am after is how to obtain the previous period latest values in the same row so that I can work out a rate of change. I have tried adding latest_by("value", time_shift(__time, 'PT1H', -1), 20) but this does not give me the desired result.
Any pointers in the right direction would be appreciated.