---
title: tickscript.groupBy() function
description: tickscript.groupBy() groups results by the _measurement column and other specified columns.
url: https://docs.influxdata.com/flux/v0/stdlib/contrib/bonitoo-io/tickscript/groupby/
estimated_tokens: 1162
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/contrib/bonitoo-io/tickscript/groupby/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.111.0+

InfluxDB support

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

`tickscript.groupBy()` groups results by the `_measurement` column and other specified columns.

This function is comparable to [Kapacitor QueryNode .groupBy](/kapacitor/latest/nodes/query_node/#groupby).

**Note**: To group by time intervals, use `window()` or `tickscript.selectWindow()`.

##### Function type signature

```js
(<-tables: stream[A], columns: [string]) => stream[A] where A: Record
```

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

## Parameters

### columns

(Required)
List of columns to group by.

### tables

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

## Examples

### Group by host and region

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

data
    |> tickscript.groupBy(columns: ["host", "region"])
```

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

View example input and output

#### Input data

|       \_time       |\_measurement|host|region|\_field|\_value|
|--------------------|-------------|----|------|-------|-------|
|2021-01-01T00:00:00Z|      m      | h1 | east |  foo  |  1.2  |
|2021-01-01T00:01:00Z|      m      | h1 | east |  foo  |  3.4  |
|2021-01-01T00:00:00Z|      m      | h2 | east |  foo  |  2.3  |
|2021-01-01T00:01:00Z|      m      | h2 | east |  foo  |  5.6  |
|2021-01-01T00:00:00Z|      m      | h3 | west |  foo  |  1.2  |
|2021-01-01T00:01:00Z|      m      | h3 | west |  foo  |  3.4  |
|2021-01-01T00:00:00Z|      m      | h4 | west |  foo  |  2.3  |
|2021-01-01T00:01:00Z|      m      | h4 | west |  foo  |  5.6  |

#### Output data

|       \_time       |\*\_measurement|\*host|\*region|\_field|\_value|
|--------------------|---------------|------|--------|-------|-------|
|2021-01-01T00:00:00Z|       m       |  h1  |  east  |  foo  |  1.2  |
|2021-01-01T00:01:00Z|       m       |  h1  |  east  |  foo  |  3.4  |

|       \_time       |\*\_measurement|\*host|\*region|\_field|\_value|
|--------------------|---------------|------|--------|-------|-------|
|2021-01-01T00:00:00Z|       m       |  h2  |  east  |  foo  |  2.3  |
|2021-01-01T00:01:00Z|       m       |  h2  |  east  |  foo  |  5.6  |

|       \_time       |\*\_measurement|\*host|\*region|\_field|\_value|
|--------------------|---------------|------|--------|-------|-------|
|2021-01-01T00:00:00Z|       m       |  h3  |  west  |  foo  |  1.2  |
|2021-01-01T00:01:00Z|       m       |  h3  |  west  |  foo  |  3.4  |

|       \_time       |\*\_measurement|\*host|\*region|\_field|\_value|
|--------------------|---------------|------|--------|-------|-------|
|2021-01-01T00:00:00Z|       m       |  h4  |  west  |  foo  |  2.3  |
|2021-01-01T00:01:00Z|       m       |  h4  |  west  |  foo  |  5.6  |

#### Related

* [Kapacitor QueryNode - groupBy](/kapacitor/v1/nodes/query_node/#groupby)

[transformations](/flux/v0/tags/transformations/)
| _time | _measurement | host | region | _field | _value |
| --- | --- | --- | --- | --- | --- |
| _time | _measurement | host | region | _field | _value |
| 2021-01-01T00:00:00Z | m | h1 | east | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h1 | east | foo | 3.4 |
| 2021-01-01T00:00:00Z | m | h2 | east | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h2 | east | foo | 5.6 |
| 2021-01-01T00:00:00Z | m | h3 | west | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h3 | west | foo | 3.4 |
| 2021-01-01T00:00:00Z | m | h4 | west | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h4 | west | foo | 5.6 |

| _time | *_measurement | *host | *region | _field | _value |
| --- | --- | --- | --- | --- | --- |
| _time | *_measurement | *host | *region | _field | _value |
| 2021-01-01T00:00:00Z | m | h1 | east | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h1 | east | foo | 3.4 |

| _time | *_measurement | *host | *region | _field | _value |
| --- | --- | --- | --- | --- | --- |
| _time | *_measurement | *host | *region | _field | _value |
| 2021-01-01T00:00:00Z | m | h2 | east | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h2 | east | foo | 5.6 |

| _time | *_measurement | *host | *region | _field | _value |
| --- | --- | --- | --- | --- | --- |
| _time | *_measurement | *host | *region | _field | _value |
| 2021-01-01T00:00:00Z | m | h3 | west | foo | 1.2 |
| 2021-01-01T00:01:00Z | m | h3 | west | foo | 3.4 |

| _time | *_measurement | *host | *region | _field | _value |
| --- | --- | --- | --- | --- | --- |
| _time | *_measurement | *host | *region | _field | _value |
| 2021-01-01T00:00:00Z | m | h4 | west | foo | 2.3 |
| 2021-01-01T00:01:00Z | m | h4 | west | foo | 5.6 |
