> For the complete documentation index, see [llms.txt](https://docs.inforiver.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.inforiver.com/formula-syntax/time-intelligence-functions/movingsum.md).

# MOVINGSUM

The MOVINGSUM formula returns the sum of a measure over a specified date range.&#x20;

## Syntax

```javascript
MOVINGSUM(measure, startDate, endDate)
```

## Arguments

measure– The measure to sum. Required.

startDate – Start date of the range. Required.

endDate- End date of the range. Required.

## Return value

Returns the sum of the measure over the specified date range.

## Example

```javascript
MOVINGSUM([Profit], CURRENT_PERIOD, SHIFT(CURRENT_PERIOD, "2M"))
//Calculates the sum of the profit for a particular month and 2 months after it

MOVINGSUM([Sales], DATE(2024,4,1), DATE(2024,8,31))
//Calculates the rolling sum between April and August 2024 
```

We've used MOVINGSUM to calculate the rolling sum of the profit measure for each month and 2 months after that month. For example, the MOVINGSUM for January would be the sum of the profits for January, February, and March.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FOgJTur9BsIcQJLjqyAhF%2Fimage.png?alt=media&amp;token=7014d4f2-1163-4a98-b803-4ad394a5a438" alt=""><figcaption><p>MOVINGSUM example</p></figcaption></figure>

You can also use MOVINGSUM with forecasts to aggregate your measures over open and closed periods. In this example, we've aggregated the forecast measure for the open periods.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FwpTLc5jIzy0Y3kzBLFop%2Fimage.png?alt=media&amp;token=dc6213a4-46f9-4f7d-bd1e-e27a1a373a72" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.inforiver.com/formula-syntax/time-intelligence-functions/movingsum.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
