---
title: average() | Tiger Data Docs
description: Calculate the time-weighted average of values in a TimeWeightSummary
---

Since [1.0.0](https://github.com/timescale/timescaledb-toolkit/releases/tag/1.0.0)

Calculate the time-weighted average. Equal to [`integral`](/docs/reference/toolkit/time_weight/integral/index.md) divided by the elapsed time. Note that there is a key difference to `avg()`: If there is exactly one value, `avg()` would return that value, but `average()` returns `NULL`.

## Samples

Calculate the time-weighted average of the column `val`, using the ‘last observation carried forward’ interpolation method:

```
SELECT
    id,
    average(tws)
FROM (
    SELECT
        id,
        time_weight('LOCF', ts, val) AS tws
    FROM foo
    GROUP BY id
) t
```

## Arguments

The syntax is:

```
average(
    tws TimeWeightSummary
) RETURNS DOUBLE PRECISION
```

| Name | Type              | Default | Required | Description                                            |
| ---- | ----------------- | ------- | -------- | ------------------------------------------------------ |
| tws  | TimeWeightSummary | -       | ✔        | The input TimeWeightSummary from a time\_weight() call |

## Returns

| Column  | Type             | Description                |
| ------- | ---------------- | -------------------------- |
| average | DOUBLE PRECISION | The time-weighted average. |
