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

# MovingCorr

> Use the Sigma MovingCorr function to calculate the Pearson correlation coefficient, also known as the bivariate correlation, of two numerical.

The **MovingCorr** function calculates the Pearson correlation coefficient, also known as the bivariate correlation, of two numerical columns within a moving window.

This function isn't compatible with all data platform connections. To check if your connection supports it, see [Supported data platforms and feature compatibility](/docs/region-warehouse-and-feature-support#supported-data-platforms-and-feature-compatibility).

## Syntax

```
MovingCorr([Number Column 1], [Number Column 2], above, below)
```

Function Arguments:

* **\[Number Column 1]** (required) - The column representing the dependent data.
* **\[Number Column 2]** (required) - The column representing the independent data.
* **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 of sales data lists quantity sold and total sales by day. You can use the **MovingCorr** function to find the relationship between the total sales of an item and the amount of an item that's purchased within several types of moving windows.

```
MovingCorr([Weekly Quantity Sold], [Total Weekly Sales], 4)
```

Here, the **above** argument is 4, so the correlation between \[Total Weekly Sales] and \[Total Quantity Sold] is computed for the previous 4 weeks. Because the **below** argument is not specified, it defaults to 0 and no future weeks are considered.

![A table with Week of date, Weekly Quantity Sold, Weekly Sales, and Moving Correlation columns, with 5 rows from 2019-05-26 to 2019-06-23 highlighted and a Moving Correlation of -0.19 highlighted on the final row, 2019-06-23.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/3d5a36f7aa16b45107af14485282cac9f248d574ed4f7bdc4a183da81a69fd1d/assets/docs-images/ac06c4f-1.png)

```
MovingCorr([Weekly Quantity Sold], [Total Weekly Sales], 0, 4)
```

Here, the **above** argument is 0, so no previous weeks are included in the calculations. The **below** average is 4, therefore the moving correlation is computed for each week along with the next 4 weeks.

![A table with Week of date, Weekly Quantity Sold, Weekly Sales, and Moving Correlation columns, with 5 rows from 2019-05-26 to 2019-06-23 highlighted and a Moving Correlation of -0.19 highlighted on the first row, 2019-05-26.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/4f2aa82c2b42c7c13f2628ded8d789431172e87120b40dca2173fe048cb9a222/assets/docs-images/75b2755-2.png)

```
MovingCorr([Weekly Quantity Sold], [Total Weekly Sales], 2, 2)
```

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

![A table with Week of date, Weekly Quantity Sold, Weekly Sales, and Moving Correlation columns, with 5 rows from 2019-05-26 to 2019-06-23 highlighted and a Moving Correlation of -0.19 highlighted on the middle row, 2019-06-09.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/fd667388e100691cf873a09ca01e1a1f61a27a6d88480090043db72eaff7934f/assets/docs-images/f969622-3.png)

```
MovingCorr([Weekly Quantity Sold], [Total 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 Quantity Sold, Weekly Sales, and Moving Correlation columns, with 5 rows from 2019-05-26 to 2019-06-23 highlighted and a Moving Correlation of 0.19 highlighted on the row for 2019-07-21.](https://files.buildwithfern.com/sigma.docs.buildwithfern.com/af487109e74dbb0e7186dcd0ce073e158bbea2e23db7f6f93d6d2a42b1362b15/assets/docs-images/3c0936e-4.png)

## Related resources

* [Corr](/docs/corr)
* [CumulativeCorr](/docs/cumulativecorr)