window() function

The window() function groups records based on a time value. The function calculates time windows and stores window bounds in the _start and _stop columns. _start and _stop values are assigned to rows based on the _time value.

A single input row may be placed into zero or more output tables depending on the parameters passed into the window() function.

    every: 5m,
    period: 5m,
    offset: 12h,
    timeColumn: "_time",
    startColumn: "_start",
    stopColumn: "_stop",
    location: "UTC",
    createEmpty: false,


Calendar months and years

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

Window 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.


Duration of time between windows. Defaults to period value.


Duration of the window. Period is the length of each interval. It can be negative, indicating the start and stop boundaries are reversed. Defaults to every value.


Offset is the duration by which to shift the window boundaries. It can be negative, indicating that the offset goes backwards in time. Defaults to 0, which will align window end boundaries with the every duration.


The column containing time. Defaults to "_time".


The column containing the window start time. Defaults to "_start".


The column containing the window stop time. Defaults to "_stop".


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

Flux uses the timezone database (commonly referred to as “tz” or “zoneinfo”) provided by the operating system.


Specifies whether empty tables should be created. Defaults to false.


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


The following examples use data provided by the sampledata package to show how window() transforms data.

Window data into 30 second intervals

import "sampledata"

data =
    |> range(start: sampledata.start, stop: sampledata.stop)

    |> window(every: 30s)

View input and output

Window every 20 seconds covering 40 second periods

import "sampledata"

data =
    |> range(start: sampledata.start, stop: sampledata.stop)

    |> window(every: 20s, period: 40s)

View input and output

Window by calendar month

The following example uses generate.from to illustrate windowing by calendar month.

import "generate"

timeRange = {start: 2021-01-01T00:00:00Z, stop: 2021-04-01T00:00:00Z}

data = generate.from(count: 6, fn: (n) => n + n, start: timeRange.start, stop: timeRange.stop)
    |> range(start: timeRange.start, stop: timeRange.stop)

    |> window(every: 1mo)

View input and output

Was this page helpful?

Thank you for your feedback!

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.