# Moving average

This Moving average step smooths out short-term fluctuations in your data by calculating averages over a specified window of time or number of rows. It's particularly helpful for identifying trends in time-series data.

### Step parameters

* `Value column` **column(string)**: the value column used as the basis for the moving average computation
* `Reference column to sort (usually dates)` **column(string)**: the column used to sort rows
* `Moving window (in number of rows)` **int\***: the number of rows included in the moving window
* `Group by` **(optional)**: if you want perform the computation by group of rows (see example 2 below)
* `New column name` **(optional)**: if you want to specify a custom column name (by default, it will be your original value column name suffixed with `_MOVING_AVG`)

### Example

**Input**

<figure><img src="/files/cYFRoSwip2RNwY5eJGpp" alt=""><figcaption><p>Compute - Moving average input</p></figcaption></figure>

**Configuration**

```json
{
    "value_col": "sales",
    "column_to_sort": "date",
    "moving_window": 3,
    "group_by": [],
    "new_column_name": "sales_moving_avg"
}
```

**Output**

<figure><img src="/files/LyIZmjHGsZ2VFPJ3vOqO" alt=""><figcaption><p>Compute - Moving average output</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-v3.toucantoco.com/data-management-in-datahub/datasets-in-toucan/preparing-data/overview-of-youprep-tm/compute/moving-average.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
