Sequential aggregate functions

Please,еell me how to calculate such data using flux. I need to take the sum of the maximums for 10 days from the data. I see it as two consecutive aggregate window functions, first with a search for the maximum with a window of 1 day, then the sum with a window of 10 days. The maximum is found correctly, but the sum for 10 days is not calculated.

water = from(bucket: "vending")
  |> range(start: 	2025-04-15T00:00:00Z, stop: 2025-04-24T00:00:00Z )
  |> filter(fn: (r) => r["_field"] == "sdw")
  |> filter(fn: (r) => r["name"] == "50_12_168" or r["name"] == "Ntz_9")
  |> aggregateWindow(every: 1d, fn: max)
  |> aggregateWindow(every: 10d, fn: sum)
  |> drop(columns: ["uidi","_start","_stop"])

Your query’s second aggregateWindow(every: 10d, fn: sum) likely misaligned windows, causing incorrect sums. Use a window operation for 10-day periods, then sum while keeping series grouping.

thanks for the reply, but I didn’t quite figure out how to do it. As I understand it, the results of the first aggregate window are transferred to the second aggregate window. I get the results of the first window that I need. Now I need to calculate the sum of these 10 rows by grouping by tag