---
title: tickscript.selectWindow() function
description: tickscript.selectWindow() changes a column’s name, windows rows by time, and then applies an aggregate or selector function the specified column for each window of time.
url: https://docs.influxdata.com/flux/v0/stdlib/contrib/bonitoo-io/tickscript/selectwindow/
estimated_tokens: 2024
product: Flux
version: v0
---

# tickscript.selectWindow() function

-   Flux 0.111.0+
-   View InfluxDB support

`tickscript.selectWindow()` is a user-contributed function maintained by the [package author](#package-author-and-maintainer).

`tickscript.selectWindow()` changes a column’s name, windows rows by time, and then applies an aggregate or selector function the specified column for each window of time.

## TICKscript helper function

`tickscript.selectWindow` is a helper function meant to replicate TICKscript operations like the following:

```
// Rename, window, and aggregate
query("SELECT f(x) AS y")
  .groupBy(time(t), ...)
```

##### Function type signature

```js
(
    <-tables: stream[D],
    as: string,
    defaultValue: A,
    every: duration,
    fn: (<-: stream[B], column: string) => stream[C],
    ?column: string,
) => stream[E] where B: Record, C: Record, D: Record, E: Record
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### column

Column to operate on. Default is \_value.

### fn

(Required) Aggregate or selector function to apply.

### as

(Required) New column name.

### every

(Required) Duration of windows.

### defaultValue

(Required) Default fill value for null values in column. Must be the same data type as column.

### tables

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

## Examples

### Change the name of, window, and then aggregate the value column

```js
import "contrib/bonitoo-io/tickscript"

data
    |> tickscript.selectWindow(fn: sum, as: "example-name", every: 1h, defaultValue: 0)
```

[](#view-example-input-and-output)

View example input and output

#### Input data

| *_start | *_stop | _time | _value | *tag |
| --- | --- | --- | --- | --- |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | -2 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 10 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | 7 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 17 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 15 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |

| *_start | *_stop | _time | _value | *tag |
| --- | --- | --- | --- | --- |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:10Z | 4 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:20Z | -3 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:30Z | 19 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:40Z | 13 | t2 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 1 | t2 |

#### Output data

| _time | *_start | *_stop | *tag | example-name |
| --- | --- | --- | --- | --- |
| 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | t1 | 51 |

| _time | *_start | *_stop | *tag | example-name |
| --- | --- | --- | --- | --- |
| 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | t2 | 53 |

#### Related

-   [tickscript.select() function](/flux/v0/stdlib/contrib/bonitoo-io/tickscript/select/)

[transformations](/flux/v0/tags/transformations/)
