> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# MovingSum

> The MovingSum functions calculates the sum of a column in a moving window.

The **MovingSum** functions calculates the sum of a column in a moving window.

## Syntax

```
MovingSum([column], above, below)
```

Function Arguments:

* **\[column]** (required) - The column of numbers to sum.
* **above** (required) - The first row to include, counting backwards from the current row.
* **below** (optional) - The last row to include, counting forward from the current row. Defaults to 0 (current row will be the last row included).

When using this function without a sort enforced, there can be unexpected results. In order to ensure that the values are stable, verify that there is a sorted column within the table.

## Example

The following table lists the weekly sales for the past year. The table is sorted ascending by the week. The **MovingSum** function can be utilized in order to calculate the sum of weekly sales within specific windows.

```
MovingSum([Weekly Sales], 4)
```

With \[Weekly Sales] as the **column** argument and 4 as the **above** argument, the sum of weekly sales is calculated for each week along with the four previous weeks. Since the **below** argument is not specified, it defaults to 0.  

![A table with Week of Date, Weekly Sales, and Moving Sum columns, highlighting the current week and four previous weeks of sales that produce a moving sum of \$64,730,867.03 for the week of 2022-08-07.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/204f5fa38ed46341bf2a7e0ef81326c6c3fd4aa27c178c3fa00fa1b32c1c5cbd/assets/docs-images/087b171-11.png)

```
MovingSum([Weekly Sales], 0, 4)
```

Here, the **above** argument is 0, so there will not be any previous weeks included in the sum calculation. The **below** average is 4, so the sum of weekly sales will be computed for each week along with the next 4 weeks.

![A table with Week of Date, Weekly Sales, and Moving Sum columns, highlighting the week of 2022-07-10 and the next four weeks of sales, which produce a moving sum of \$64,509,478.32 for that week.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/52b92438c14a734bdbbc0f93854e692ce804cc5eff23e3c9abbfd40e849c46bc/assets/docs-images/336852f-22.png)

```
MovingSum([Weekly Sales], 2, 2)
```

Here, the **above** argument is 2, so the previous two weeks are included in the sum calculation. In addition, the **below** argument is 2, so the following two weeks are included as well.

![A table with Week of Date, Weekly Sales, and Moving Sum columns, highlighting the two weeks before and after 2022-07-24, which produce a moving sum of \$64,509,478.32 for that week.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/0d11012839bed92082c622d28d5721d288248126bdd65bc65a50ae881e7a0d9b/assets/docs-images/6abac33-33.png)

```
MovingSum([Weekly Sales], 8, -4)
```

Here is an example where the **below** parameter is negative. The **below** parameter can be negative as long as the value is less than that of the **above** parameter. In this example, each window begins 8 weeks before the current week and ends 4 weeks before the current week, inclusive.

![A table with Week of Date, Weekly Sales, and Moving Sum columns, highlighting the window from eight to four weeks before 2022-09-04, which produces a moving sum of \$64,509,478.32 for that week.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/70f6306c2f53e751635b9703e20aa871f78bcb5e224fc5749f137c2a2e35397e/assets/docs-images/f0d4fd7-44.png)

## Related resources

* [Sum](/docs/sum)
* [CumulativeSum](/docs/cumulativesum)