> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Calculates the moving average of input values.

# groupArrayMovingAvg

<h2 id="groupArrayMovingAvg">
  groupArrayMovingAvg
</h2>

Introduced in: v20.1.0

Calculates the moving average of input values.

<Note>
  The function uses rounding towards zero.
  It truncates the decimal places insignificant for the resulting data type.
</Note>

**Syntax**

```sql theme={null}
groupArrayMovingAvg(numbers_for_summing)
groupArrayMovingAvg(window_size)(numbers_for_summing)
```

**Parameters**

* `window_size` — Size of the calculation window. If left unspecified, the function takes the window size equal to the number of rows in the column. [`UInt64`](/reference/data-types/int-uint)

**Arguments**

* `numbers_for_summing` — Expression resulting in a numeric data type value. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal`](/reference/data-types/decimal)

**Returned value**

Returns an array of the same size as the input data. For non-Decimal input, the array contains Float64 values. For Decimal input, the array contains Decimal values with the input scale. [`Array`](/reference/data-types/array)

**Examples**

**Usage example**

```sql title=Query theme={null}
CREATE TABLE t
(
    `int` UInt8,
    `float` Float32,
    `dec` Decimal32(2)
)
ENGINE = Memory;

INSERT INTO t VALUES (1, 1.1, 1.10), (2, 2.2, 2.20), (4, 4.4, 4.40), (7, 7.77, 7.77);

SELECT
    groupArrayMovingAvg(int) AS I,
    groupArrayMovingAvg(float) AS F,
    groupArrayMovingAvg(dec) AS D
FROM t;
```

```response title=Response theme={null}
┌─I────────────────────┬─F─────────────────────────────────────────────────────────────────────────────┬─D─────────────────────┐
│ [0.25,0.75,1.75,3.5] │ [0.2750000059604645,0.8250000178813934,1.9250000417232513,3.8675000369548798] │ [0.27,0.82,1.92,3.86] │
└──────────────────────┴───────────────────────────────────────────────────────────────────────────────┴───────────────────────┘
```

**With window size**

```sql title=Query theme={null}
SELECT
    groupArrayMovingAvg(2)(int) AS I,
    groupArrayMovingAvg(2)(float) AS F,
    groupArrayMovingAvg(2)(dec) AS D
FROM t;
```

```response title=Response theme={null}
┌─I───────────────┬─F───────────────────────────────────────────────────────────────────────────┬─D─────────────────────┐
│ [0.5,1.5,3,5.5] │ [0.550000011920929,1.6500000357627869,3.3000000715255737,6.085000038146973] │ [0.55,1.65,3.30,6.08] │
└─────────────────┴─────────────────────────────────────────────────────────────────────────────┴───────────────────────┘
```
