aggregateWindow() function

The aggregateWindow() function applies an aggregate or selector function (any function with a column parameter) to fixed windows of time.

Function type: Aggregate

  every: 1m,
  fn: mean,
  column: "_value",
  timeSrc: "_stop",
  timeDst: "_time",
  createEmpty: true

As data is windowed into separate tables and processed, the _time column is dropped from each group key. This function copies the timestamp from a remaining column into the _time column.

aggregateWindow() restores the original _start and _stop values of input data and, by default, uses _stop to set the _time value for each aggregated window. Each row in the output of aggregateWindow represents an aggregated window ending at _time.


Make sure fn parameter names match each specified parameter. To learn why, see Match parameter names.


The duration of windows.

Calendar months and years

every supports all valid duration units, including calendar months (1mo) and years (1y).

Data type: Duration


The aggregate or selector function used in the operation.

Data type: Function

Only aggregate and selector functions with a column parameter (singular) work with aggregateWindow().


The column on which to operate. Defaults to "_value".

Data type: String


The time column from which time is copied for the aggregate record. Defaults to "_stop".

Data type: String


The “time destination” column to which time is copied for the aggregate record. Defaults to "_time".

Data type: String


For windows without data, create a single-row table for each empty window (using table.fill()). Defaults to true.

Data type: Boolean

When using createEmpty: true, aggregate functions return empty tables, but selector functions do not. By design, selectors drop empty tables.


The examples below use a data variable to represent a filtered data set.

data = from(bucket: "example-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) =>
    r._measurement == "mem" and
    r._field == "used_percent")
Use an aggregate function with default parameters

The following example uses the default parameters of the mean() function to aggregate time-based windows:

  |> aggregateWindow(
    every: 5m,
    fn: mean
Specify parameters of the aggregate function

To use functions that don’t provide defaults for required parameters with aggregateWindow(), define an anonymous function with column and tables parameters that pipes-forward tables into the aggregate or selector function with all required parameters defined:

  |> aggregateWindow(
    column: "_value",
    every: 5m,
    fn: (column, tables=<-) => tables |> quantile(q: 0.99, column:column)
Window and aggregate by calendar month
  |> aggregateWindow(every: 1mo, fn: mean)

Set your InfluxDB URL

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.