> 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.

# MovingCount

The **MovingCount** function counts the number of non-null values within a column in a moving window.

## Syntax

```
MovingCount([Column], above, below)
```

Function Arguments

* **\[Column]** (required) - The column of numbers, text, or dates to count. Null values are skipped.
* **above** (required) - The first row to include, counting backward 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

A table contains data about the amount of violations found by day during inspections in restaurants.  The **MovingCount** function can be used to find the number of non-null values within different moving windows.

```
MovingCount([Violations], 4)
```

With \[Violations] as the **column** argument and 4 as the **above** argument, the number of non-null values are calculated for each day along with the four previous days. Since the **below** argument was not specified, it defaults to 0.  

![A table with Day of date, Violations, and Moving Count columns, with 5 Violations cells from 2014-02-04 to 2014-02-10 highlighted (2 of which are null) and a Moving Count of 3 highlighted on the final row, 2014-02-10.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/b4bb0046677782ecb2f78b7a020d3ceb294243a9692c2163c7b0b902a10869e9/assets/docs-images/8a4c0ff-11.png)

```
MovingCount([Violations], 0, 4)
```

Here, the **above** argument is 0, so no previous days are included in the count. The **below** average is 4, so the count is computed for each day along with the next 4 days.

![A table with Day of date, Violations, and Moving Count columns, with 5 Violations cells from 2014-02-04 to 2014-02-10 highlighted (2 of which are null) and a Moving Count of 3 highlighted on the first row, 2014-02-04.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/a7e436ca6c34fefdb722175eb49a5e842aff303ad0fad9e1148ff6397eaad87a/assets/docs-images/8bb53a3-22.png)

```
MovingCount([Violations], 2, 2)
```

Here, the **above** argument is 2, so the previous two days will be included in the count. In addition, the **below** argument is 2, so the following two days will be included as well.

![A table with Day of date, Violations, and Moving Count columns, with 5 Violations cells from 2014-02-04 to 2014-02-10 highlighted (2 of which are null) and a Moving Count of 3 highlighted on the middle row, 2014-02-06.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/09c29def53b3426a9f670771c9c2257d76c63b799bbd395f082c583f63aecea0/assets/docs-images/568808b-33.png)

```
MovingCount([Violations], 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 days before the current day and ends 4 days before the current week, inclusive.

![A table with Day of date, Violations, and Moving Count columns, with 5 Violations cells from 2014-02-04 to 2014-02-10 highlighted (2 of which are null) and a Moving Count of 3 highlighted on the row for 2014-02-14.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/c9712525addc2b77b83267d3a42edbe5b16f92958888a22fc65946f298335bb4/assets/docs-images/5e97f41-44.png)

## Related resources

* [Count](/docs/count)
* [CumulativeCount](/docs/cumulativecount)