Documentation

aggregateWindow() function

aggregateWindow() downsamples data by grouping data into fixed windows of time and applying an aggregate or selector function to each window.

All columns not in the group key other than the specified column are dropped from output tables. This includes _time. aggregateWindow() uses the timeSrc and timeDst parameters to assign a time to the aggregate value.

aggregateWindow() requires _start and _stop columns in input data. Use range() to assign _start and _stop values.

This function is intended to be used when timeColumn (_time by default) is not in the group key. If timeColumn is in the group key, resulting output is confusing and generally not useful.

Downsample by calendar months and years

every, period, and offset parameters support all valid duration units, including calendar months (1mo) and years (1y).

Downsample by week

When windowing by week (1w), weeks are determined using the Unix epoch (1970-01-01T00:00:00Z UTC). The Unix epoch was on a Thursday, so all calculated weeks begin on Thursday.

Function type signature
(  <-tables: stream[D],  every: duration,  fn: (<-: stream[B], column: A) => stream[C],  ?column: A,  ?createEmpty: bool,  ?location: {zone: string, offset: duration},  ?offset: duration,  ?period: duration,  ?timeDst: string,  ?timeSrc: string, ) => stream[E] where B: Record, C: Record, D: Record, E: Record

For more information, see Function type signatures.

Parameters

every

(Required) Duration of time between windows.

period

Duration of windows. Default is the every value.

period can be negative, indicating the start and stop boundaries are reversed.

offset

Duration to shift the window boundaries by. Default is 0s.

offset can be negative, indicating that the offset goes backwards in time.

fn

(Required) Aggregate or selector function to apply to each time window.

location

Location used to determine timezone. Default is the location option.

column

Column to operate on.

timeSrc

Column to use as the source of the new time value for aggregate values. Default is _stop.

timeDst

Column to store time values for aggregate values in. Default is _time.

createEmpty

Create empty tables for empty window. Default is true.

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

tables

Input data. Default is piped-forward data (<-).

Examples

Use an aggregate function with default parameters

data  |> aggregateWindow(every: 20s, fn: mean)

View example input and output

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:

data  |> aggregateWindow(  column: "_value",  every: 20s,  fn: (column, tables=<-) => tables |> quantile(q: 0.99, column: column),  )

View example input and output

Downsample by calendar month

data  |> aggregateWindow(every: 1mo, fn: mean)

View example input and output

Downsample by calendar week starting on Monday

Flux increments weeks from the Unix epoch, which was a Thursday. Because of this, by default, all 1w windows begin on Thursday. Use the offset parameter to shift the start of weekly windows to the desired day of the week.

Week startOffset
Monday-3d
Tuesday-2d
Wednesday-1d
Thursday0d
Friday1d
Saturday2d
Sunday3d
data  |> aggregateWindow(every: 1w, offset: -3d, fn: mean)

View example input and output


Was this page helpful?

Thank you for your feedback!


New in InfluxDB 3.5

Key enhancements in InfluxDB 3.5 and the InfluxDB 3 Explorer 1.3.

See the Blog Post

InfluxDB 3.5 is now available for both Core and Enterprise, introducing custom plugin repository support, enhanced operational visibility with queryable CLI parameters and manual node management, stronger security controls, and general performance improvements.

InfluxDB 3 Explorer 1.3 brings powerful new capabilities including Dashboards (beta) for saving and organizing your favorite queries, and cache querying for instant access to Last Value and Distinct Value caches—making Explorer a more comprehensive workspace for time series monitoring and analysis.

For more information, check out:

InfluxDB Docker latest tag changing to InfluxDB 3 Core

On November 3, 2025, the latest tag for InfluxDB Docker images will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments.

If using Docker to install and run InfluxDB, the latest tag will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments. For example, if using Docker to run InfluxDB v2, replace the latest version tag with a specific version tag in your Docker pull command–for example:

docker pull influxdb:2