> ## Documentation Index
> Fetch the complete documentation index at: https://docs.invoca.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Moving Functions

> Moving formulas smooth out irregularities in your data across a defined window, making trends easier to recognize.

Moving formulas smooth out irregularities in your data so trends are easier to recognize. Larger intervals smooth out more peaks and troughs; smaller intervals keep the moving formula closer to the actual data points.

## Syntax

Each moving formula accepts a **Measure**, two integers defining the **window** or **interval**, and one or more optional **attributes**:

```text theme={null}
formula ( Measure, windowStart, windowFinish, [attribute1, attribute2, ...] )
```

Moving formulas require only the Measure and the integer values. If you don't specify attributes, the function reverts to a non-moving Measure — in other words, `moving_sum()` functions as `sum()`. When you specify both required and optional values, the formula returns the aggregate of the Measure over the provided attributes for the defined window.

Invoca determines the window with the following formula:

```text theme={null}
current row - integer1, current row + integer2
```

So a window of `(1,1)` contains 3 rows total: one row before the current row, the current row, and one row after. You can emulate "lag" by specifying negative values for the window — for example, a window of `(1,-1)` contains only 1 row, the one that precedes the current row.

<Note>
  **Note**

  When the windowing attribute is character-based, Invoca orders values alphanumerically to determine row order for the window calculation.
</Note>

## The moving formulas

| Function         | Description                                  | Example                                           |
| :--------------- | :------------------------------------------- | :------------------------------------------------ |
| `moving_average` | Average of the Measure over the given window | `moving_average (revenue, 2, 1, customer region)` |
| `moving_max`     | Maximum of the Measure over the given window | `moving_max (complaints, 1, 2, store name)`       |
| `moving_min`     | Minimum of the Measure over the given window | `moving_min (defects, 3, 1, product)`             |
| `moving_sum`     | Sum of the Measure over the given window     | `moving_sum (revenue, 1, 1, order date)`          |

## Calculate a moving average

1. Start a new search.
2. In the upper-right of the table, click the **more options** menu icon and select **Add formula**.
3. Enter the `moving_average` formula, specifying a Measure, the window, and one or more attributes.
4. Name the formula by entering a title in the top field, then click **Save**. It appears in the search bar and as its own table column, with a box showing the moving average within the entire table at the bottom of the chart.
5. To use a different aggregation type, click the current aggregation type at the bottom of the box and select another.

## Where to go next

* [Cumulative functions](/s/article/cumulative-functions)
* [Flexible aggregation functions](/s/article/flexible-aggregation-functions)
* [Group aggregation functions](/s/article/group-aggregation-functions)
* [Filtered aggregation functions](/s/article/filtered-aggregation-functions)
