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

# Time-based aggregations

Plan supports time-based aggregation functions that help you analyze measure values across a specified time period. These functions enable you to calculate rolling values and perform aggregations over date ranges.

### AGGREGATE

The *AGGREGATE* function performs an aggregation on a measure over a specified date range. It supports aggregation methods such as average, sum, minimum, maximum, and median.

#### Syntax

```
AGGREGATE(measure, startDate, endDate, aggregationType)
```

#### Arguments

* `measure`: The measure on which the aggregation is performed.
* `startDate`: The start date of the date range.
* `endDate`: The end date of the date range.
* `aggregationType`: Specifies the aggregation method to apply. Supported values include `AVG`, `SUM`, `MIN`, `MAX`, and `MEDIAN`.

#### Return value

Returns the aggregated value of the specified measure over the given date range.

#### Examples

```
AGGREGATE([Sales], SHIFT(COLUMN.CURRENT_PERIOD, "-3M"), SHIFT(CURRENT_PERIOD, "-1M"), "MAX")
```

Returns the maximum *Sales* value for the specified date range. In this example, the function returns the maximum sales over the previous three months.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2Fx8izkIWS6jzLr0Um1egn%2Fimage.png?alt=media&amp;token=721a9f69-4485-4947-adf7-a3f742d44b8c" alt=""><figcaption></figcaption></figure>

```
AGGREGATE([Sales], DATE(2025,4,1), DATE(2025,7,31), "MEDIAN")
```

Returns the median *Sales* value for the specified date range. In this example, the function returns the median sales between April 1, 2025 and July 31, 2025.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FBuwmdIDh2lJ8DtMu2pYC%2Fimage.png?alt=media&amp;token=d5dd49b5-bf94-4fad-89ee-173f8847a5f5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(19).png" alt=""><figcaption></figcaption></figure>

### MOVINGAVERAGE

The *MOVINGAVERAGE* function returns the average of a measure over a specified date range.

#### Syntax

```
MOVINGAVERAGE(measure, startDate, endDate)
```

#### Arguments

* `measure`: The measure for which the average is calculated.
* `startDate`: The start date of the date range.
* `endDate`: The end date of the date range.

#### Return value

Returns the average of the specified measure over the given date range.

#### Examples

```
MOVINGAVERAGE([Sales], COLUMN.CURRENT_PERIOD, SHIFT(COLUMN.CURRENT_PERIOD, "2M"))
```

Returns the average *Sales* value for the current period and the following two months. For example, the moving average for January is calculated using the *Sales* values for January, February, and March.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FT0svKwsohuQ1UFBnNsfh%2Fimage.png?alt=media&amp;token=2f212d1a-eeca-4570-8cd0-6d75cb8e7578" alt=""><figcaption></figcaption></figure>

```
MOVINGAVERAGE([Sales], DATE(2025,4,1), DATE(2025,8,31))
```

Returns the average *Sales* value between **April 1, 2025** and **August 31, 2025**.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FLMXRCmgKWTXriQCWmUN0%2Fimage.png?alt=media&amp;token=b23357f7-73c6-4bf4-849d-b6ca61879c00" alt=""><figcaption></figcaption></figure>

You can also use the *MOVINGAVERAGE* function with forecast measures to calculate averages across open and closed periods.

```
MOVINGAVERAGE([Forecast], [Forecast].OPEN_START, [Forecast].OPEN_END)
```

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F1yXZk7T0KYLcUwRNNApj%2Fimage.png?alt=media&amp;token=573e81fd-7d6b-4b2f-a736-40218a60a2fb" alt=""><figcaption></figcaption></figure>

### MOVINGSUM

The *MOVINGSUM* function returns the sum of a measure over a specified date range.

#### Syntax

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

#### Arguments

* `measure`: The measure for which the sum is calculated.
* `startDate`: The start date of the date range.
* `endDate`: The end date of the date range.

#### Return value

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

#### Examples

```
MOVINGSUM([Sales], COLUMN.CURRENT_PERIOD, SHIFT(COLUMN.CURRENT_PERIOD, "2M"))
```

Returns the sum of the *Sales* values for the current period and the following two months. For example, the moving sum for January is calculated using the *Sales* values for January, February, and March.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FF6JlnaSkJbY9JLvUweSQ%2Fimage.png?alt=media&amp;token=e0ac300f-cc08-4da5-a0ad-b9dc83ffa858" alt=""><figcaption></figcaption></figure>

```
MOVINGSUM([Sales], DATE(2024,4,1), DATE(2024,8,31))
```

Returns the sum of the *Sales* values between **April 1, 2025** and **August 31, 2025**.

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2F5uLi2Kq7CQN3aHObZZk5%2Fimage.png?alt=media&amp;token=401b1ca4-44fa-44e3-b5f0-55f07e133e4e" alt=""><figcaption></figcaption></figure>

You can also use the *MOVINGSUM* function with forecast measures to calculate sums across open and closed periods.

```
MOVINGSUM([Forecast], [Forecast].OPEN_START, [Forecast].OPEN_END)
```

<figure><img src="https://257222532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUtolck8kt8atqxFPsEBn%2Fuploads%2FUXKHHqJazDuuQuZOzn7H%2Fimage.png?alt=media&amp;token=8df3e7c0-faf0-42c9-aaac-e3c84b184bed" alt=""><figcaption></figcaption></figure>

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(21).png" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fabricplan.com/planning-sheets/reference/formula-syntax/time-intelligence-functions/time-based-aggregations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
