I have this simple raw data:
timestamp | field1 | field2 | tags |
---|---|---|---|
2025-02-20T06:20:00Z | 10.0 | 40.0 | “tag1”: “v100” |
2025-02-20T06:24:00Z | 20.0 | 30.0 | “tag1”: “v100” |
2025-02-20T06:28:00Z | 30.0 | 20.0 | “tag1”: “v100” |
2025-02-20T06:32:00Z | 40.0 | 10.0 | “tag1”: “v100” |
My question is:
How can I get the exact date-time of the min and max values measured using aggregateWindow?
The desired output:
field | function | time | value |
---|---|---|---|
field1 | min | 2025-02-20T06:20:00Z | 10.0 |
field1 | max | 2025-02-20T06:32:00Z | 40.0 |
field2 | min | 2025-02-20T06:32:00Z | 10.0 |
field2 | max | 2025-02-20T06:20:00Z | 40.0 |
This is my flux script: for just getting the max. Once I get the associated timestamp then I will union the min and max.
from(bucket:“bucket001”)
|> range(start:2020-03-17T00:00:00.000000000Z, stop:2025-03-18T00:00:00.000000000Z)
|> filter(fn: (r) => (r[“_measurement”] == “main” and r[“id”] == “32373957-4186-4374-a925-c0911cf193f6”))
|> sort()
|> aggregateWindow(every:1h, fn:max, timeSrc:“_start”, createEmpty:false)
|> toFloat()
|> group()