exponentialTimeDecayedAvg

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/sql-reference/aggregate-functions/reference/exponentialTimeDecayedAvg.md)

## exponentialTimeDecayedAvg[​](#exponentialTimeDecayedAvg "Direct link to exponentialTimeDecayedAvg")

Introduced in: v21.12.0

Returns the exponentially smoothed weighted moving average of values of a time series at point `t` in time.

**Syntax**

```
exponentialTimeDecayedAvg(x)(v, t)
```

**Parameters**

- `x` — Half-life period. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)

**Arguments**

- `v` — Value. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `t` — Time. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Returned value**

Returns an exponentially smoothed weighted moving average at index `t` in time. [`Float64`](/docs/sql-reference/data-types/float)

**Examples**

**Window function usage with visual representation**

```
SELECT
    value,
    time,
    round(exp_smooth, 3),
    bar(exp_smooth, 0, 5, 50) AS bar
FROM
    (
    SELECT
    (number = 0) OR (number >= 25) AS value,
    number AS time,
    exponentialTimeDecayedAvg(10)(value, time) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS exp_smooth
    FROM numbers(50)
    )
```

```
┌─value─┬─time─┬─round(exp_smooth, 3)─┬─bar────────┐
│     1 │    0 │                    1 │ ██████████ │
│     0 │    1 │                0.475 │ ████▊      │
│     0 │    2 │                0.301 │ ███        │
│     0 │    3 │                0.214 │ ██▏        │
│     0 │    4 │                0.162 │ █▌         │
│     0 │    5 │                0.128 │ █▎         │
│     0 │    6 │                0.104 │ █          │
│     0 │    7 │                0.086 │ ▊          │
│     0 │    8 │                0.072 │ ▋          │
│     0 │    9 │                0.061 │ ▌          │
│     0 │   10 │                0.052 │ ▌          │
│     0 │   11 │                0.045 │ ▍          │
│     0 │   12 │                0.039 │ ▍          │
│     0 │   13 │                0.034 │ ▎          │
│     0 │   14 │                 0.03 │ ▎          │
│     0 │   15 │                0.027 │ ▎          │
│     0 │   16 │                0.024 │ ▏          │
│     0 │   17 │                0.021 │ ▏          │
│     0 │   18 │                0.018 │ ▏          │
│     0 │   19 │                0.016 │ ▏          │
│     0 │   20 │                0.015 │ ▏          │
│     0 │   21 │                0.013 │ ▏          │
│     0 │   22 │                0.012 │            │
│     0 │   23 │                 0.01 │            │
│     0 │   24 │                0.009 │            │
│     1 │   25 │                0.111 │ █          │
│     1 │   26 │                0.202 │ ██         │
│     1 │   27 │                0.283 │ ██▊        │
│     1 │   28 │                0.355 │ ███▌       │
│     1 │   29 │                 0.42 │ ████▏      │
│     1 │   30 │                0.477 │ ████▊      │
│     1 │   31 │                0.529 │ █████▎     │
│     1 │   32 │                0.576 │ █████▊     │
│     1 │   33 │                0.618 │ ██████▏    │
│     1 │   34 │                0.655 │ ██████▌    │
│     1 │   35 │                0.689 │ ██████▉    │
│     1 │   36 │                0.719 │ ███████▏   │
│     1 │   37 │                0.747 │ ███████▍   │
│     1 │   38 │                0.771 │ ███████▋   │
│     1 │   39 │                0.793 │ ███████▉   │
│     1 │   40 │                0.813 │ ████████▏  │
│     1 │   41 │                0.831 │ ████████▎  │
│     1 │   42 │                0.848 │ ████████▍  │
│     1 │   43 │                0.862 │ ████████▌  │
│     1 │   44 │                0.876 │ ████████▊  │
│     1 │   45 │                0.888 │ ████████▉  │
│     1 │   46 │                0.898 │ ████████▉  │
│     1 │   47 │                0.908 │ █████████  │
│     1 │   48 │                0.917 │ █████████▏ │
│     1 │   49 │                0.925 │ █████████▏ │
└───────┴──────┴──────────────────────┴────────────┘
```

- [exponentialTimeDecayedAvg](#exponentialTimeDecayedAvg)

Was this page helpful?