---
title: timeWeightedAvg() function
description: timeWeightedAvg() returns the time-weighted average of non-null values in _value column as a float for each input table.
url: https://docs.influxdata.com/flux/v0/stdlib/universe/timeweightedavg/
estimated_tokens: 908
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/universe/timeweightedavg/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.83.0+

InfluxDB support

`timeWeightedAvg()` returns the time-weighted average of non-null values in`_value` column as a float for each input table.

Time is weighted using the linearly interpolated integral of values in the table.

##### Function type signature

```js
(<-tables: stream[A], unit: duration) => stream[{B with _value: float, _value: float, _stop: D, _start: C}] where A: Record
```

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

## Parameters

### unit

(Required)
Unit of time to use to compute the time-weighted average.

### tables

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

## Examples

### Calculate the time-weighted average of values

```js
data
    |> timeWeightedAvg(unit: 1s)
```

[](#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:20Z|   7   | 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|       | 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:50Z|   1   | t2  |

#### Output data

|     \*\_start      |      \*\_stop      |     \_value     |\*tag|
|--------------------|--------------------|-----------------|-----|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|4.166666666666667| t1  |

|     \*\_start      |      \*\_stop      |     \_value     |\*tag|
|--------------------|--------------------|-----------------|-----|
|2021-01-01T00:00:00Z|2021-01-01T00:01:00Z|5.416666666666667| t2  |

#### Related

* [integral() function](/flux/v0/stdlib/universe/integral/)

[transformations](/flux/v0/tags/transformations/)[aggregates](/flux/v0/tags/aggregates/)
| *_start | *_stop | _time | _value | *tag |
| --- | --- | --- | --- | --- |
| *_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:20Z | 7 | t1 |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:50Z | 4 | t1 |

| *_start | *_stop | _time | _value | *tag |
| --- | --- | --- | --- | --- |
| *_start | *_stop | _time | _value | *tag |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 2021-01-01T00:00:00Z |  | 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:50Z | 1 | t2 |

| *_start | *_stop | _value | *tag |
| --- | --- | --- | --- |
| *_start | *_stop | _value | *tag |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 4.166666666666667 | t1 |

| *_start | *_stop | _value | *tag |
| --- | --- | --- | --- |
| *_start | *_stop | _value | *tag |
| 2021-01-01T00:00:00Z | 2021-01-01T00:01:00Z | 5.416666666666667 | t2 |
