2021-11-14 13:52:07 +00:00
---
toc_priority: 108
---
2021-11-13 20:18:59 +00:00
## exponentialMovingAverage {#exponential-moving-average}
An aggregate function that calculates the exponential moving average of values for the determined time.
**Syntax**
```sql
exponentialMovingAverage(x)(value, timestamp)
```
Each `value` corresponds to the determinate `timestamp` . The half-decay period is the time interval `x` during which the previous values are taken into account. The function returns a weighted average: the older the time point, the less weight the corresponding value is considered to be.
**Arguments**
2021-11-16 09:59:50 +00:00
2021-11-16 09:55:59 +00:00
- `value` — Value. [Integer ](../../../sql-reference/data-types/int-uint.md ), [Float ](../../../sql-reference/data-types/float.md ), or [Decimal ](../../../sql-reference/data-types/decimal.md ).
2021-11-16 09:59:56 +00:00
- `timestamp` — Timestamp must. [Integer ](../../../sql-reference/data-types/int-uint.md ).
2021-11-13 20:18:59 +00:00
**Parameters**
2021-11-16 09:56:19 +00:00
- `x` — Half-life period. [Integer ](../../../sql-reference/data-types/int-uint.md ).
2021-11-13 20:18:59 +00:00
2021-11-16 09:56:42 +00:00
**Returned values**
2021-11-13 20:18:59 +00:00
- Returnes an exponentially smoothed moving average of the values for the past `x` time at the latest point of time.
Type: [Float64 ](../../../sql-reference/data-types/float.md#float32-float64 ).
**Example**
Input table:
``` text
┌──temperature─┬─timestamp──┐
│ 95 │ 1 │
│ 95 │ 2 │
│ 95 │ 3 │
│ 96 │ 4 │
│ 96 │ 5 │
│ 96 │ 6 │
│ 96 │ 7 │
│ 97 │ 8 │
│ 97 │ 9 │
│ 97 │ 10 │
│ 97 │ 11 │
│ 98 │ 12 │
│ 98 │ 13 │
│ 98 │ 14 │
│ 98 │ 15 │
│ 99 │ 16 │
│ 99 │ 17 │
│ 99 │ 18 │
│ 100 │ 19 │
│ 100 │ 20 │
└──────────────┴────────────┘
```
Query:
```sql
exponentialMovingAverage(5)(temperature, timestamp)
```
Result:
``` text
┌──exponentialMovingAverage(5)(temperature, timestamp)──┐
│ 92.25779635374204 │
└───────────────────────────────────────────────────────┘
```