Hello @XXYYZZ,
You’re correct this is non trivial with flux.
Here I did something similar
But yikes.
I honestly would recommend querying the data with API or client library and doing this processing elsewhere and writing the data back into influxdb.
Sorry I can’t be of better assistance.