Question about WIndow Period/aggregateWindow

Just trying to understand what this WIndow Period/aggregateWindow does. When I change the time period it tends to change the value of the mean that im taking. If my understanding is correct it takes the point at every 15 minute intervals if I have the window set to 15m? Is this correct or am I off the mark?

@gatortech12 Great question and welcome to the community! aggregateWindow() splits data into time-based “windows” and applies and aggregate function to the data in each window. The every parameter specifies how often each window should start, but the period parameter specifies how long each window should last. By default, the period is the same as the every parameter, but they can be different. For example:

// ...
    |> range(start: 2024-01-01T00:00:00Z, stop: 2024-01-02T00:00:00Z)
    |> aggregateWindow(every: 1h, period: 1h30m, fn: mean)

With the query above, you get windows that start every hour, but last for 1.5 hours. So you actually get overlapping windows:

  • 2024-01-01T00:00:00.000000000Z to 2024-01-01T01:29:59.999999999Z
  • 2024-01-01T01:30:00.000000000Z to 2024-01-01T02:59:59.999999999Z
  • 2024-01-01T03:00:00.000000000Z to 2024-01-01T04:29:59.999999999Z
  • etc.

Or you could do a query where you want to average only the first 15 minutes of each hour:

// ...
    |> range(start: 2024-01-01T00:00:00Z, stop: 2024-01-02T00:00:00Z)
    |> aggregateWindow(every: 1h, period: 15m, fn: mean)

With this query, you’d get the following windows:

  • 2024-01-01T00:00:00.000000000Z to 2024-01-01T00:14:59.999999999Z
  • 2024-01-01T01:00:00.000000000Z to 2024-01-01T01:14:59.999999999Z
  • 2024-01-01T02:00:00.000000000Z to 2024-01-01T02:14:59.999999999Z
  • etc.

In most use cases, the period should be same as the every parameter, but there are some edge cases where they need to be different.

Hopefully this helps.