---
title: Rollup
description: >-
  Control time aggregation and data point intervals using custom rollup
  functions and moving rollups for metrics.
breadcrumbs: Docs > Dashboards > Functions > Rollup
---

# Rollup

Every metric query is inherently aggregated. However, appending the `.rollup()` function at the end of a query allows you to perform custom [time aggregation](https://docs.datadoghq.com/dashboards/functions/#add-a-function) that overrides the defaults. This function enables you to define:

- The rollup `<interval>`: the interval of time your data is aggregated over (if larger than the query-enforced rollup interval).
- The rollup `<aggregator>`: How your data points are aggregated within a given rollup time interval.

To apply a rollup, navigate to the **Add function** (Σ) button of the graphing editor:

{% video
   url="https://datadog-docs.imgix.net/images/dashboards/functions/rollup/rollup_option_1.mp4" /%}

**Note**: The Distribution Metric type does not have a rollup `aggregator` parameter. This metric type is aggregated both in time and space. See the documentation on [rollup for distributions with percentiles](https://docs.datadoghq.com/metrics/faq/rollup-for-distributions-with-percentiles/) to learn more.

The function takes two parameters, `<AGGREGATOR>` and optionally `<INTERVAL>`: `.rollup(<AGGREGATOR>,<INTERVAL>)` or `.rollup(<AGGREGATOR>)`.

| Parameter      | Description                                                                                                                                      |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `<AGGREGATOR>` | Can be `avg`, `sum`, `min`, `max`, or `count`, and defines how data points are aggregated within a given time interval. Enforced default: `avg`. |
| `<INTERVAL>`   | Time (in seconds) of the interval between two data points displayed. Optional.                                                                   |

You can use them individually or together, for instance `.rollup(sum,120)`. The following bar graph displays a week's worth of CPU usage for a host **without** using the `.rollup()` function:

{% image
   source="https://datadog-docs.imgix.net/images/dashboards/functions/rollup/smooth_1.c5b05f41079220c1455c4bfd6ce6874b.png?auto=format"
   alt="smooth_1" /%}

The following bar graph displays the same metric, graphed using a day-long rollup with `.rollup(avg,86400)`:

{% image
   source="https://datadog-docs.imgix.net/images/dashboards/functions/rollup/smooth_2.a1c7b69d92b8fc16af03b029e43067e8.png?auto=format"
   alt="smooth_2" /%}

## Moving rollup{% #moving-rollup %}

| Function        | Description                                         | Example                                                   |
| --------------- | --------------------------------------------------- | --------------------------------------------------------- |
| `moving_rollup` | Rollup to combine the points in the last X seconds. | `moving_rollup(<METRIC_NAME>, <INTERVAL> , <AGGREGATOR>)` |

Applying the `moving_rollup()` function to a query allows you to combine points from the most recent specified time range—that is, the last X seconds. Like with `.rollup()`, `<AGGREGATOR>` can be `sum`/`min`/`max`/`count`/`avg` and defines how data points are aggregated within the given time interval.

## Rollup interval: enforced vs custom{% #rollup-interval-enforced-vs-custom %}

When graphing, Datadog sets a limit on the number of points per timeseries. To retain visual clarity, a series can have up to 1500 points. To respect this limit, Datadog rolls up datapoints automatically, defaulting to the `avg` method, effectively displaying the average of all datapoints within a time interval for a given metric. The default rollup time interval varies depending on how the data is visualized. See the following chart to reference these default time intervals:

| Timeframe           | Rollup Interval, Line Graph | Rollup Interval, Bar Graph | Rollup Interval, API |
| ------------------- | --------------------------- | -------------------------- | -------------------- |
| The past hour       | 20s                         | 1m                         | 20s                  |
| The past four hours | 1m                          | 2m                         | 1m                   |
| The past day        | 5m                          | 20m                        | 5m                   |
| The past two days   | 10m                         | 30m                        | 10m                  |
| The past week       | 1hr                         | 2hr                        | 1hr                  |
| The past month      | 4hr                         | 12hr                       | 4hr                  |

A custom `.rollup()` function can be used to enforce the type of time aggregation applied (`avg`, `min`, `max`, `count`, or `sum`) and optionally the time interval to rollup. Using this function, you can set the rollup time interval to a different value than the defaults, up to a limit of 1500 points. This supports up to one point per minute over a day.

**Note**: Queries for `COUNT` and `RATE` type metrics have the `.as_count()` modifier appended automatically in the UI, which sets the rollup method used to `sum` and disables interpolation. This `.as_count()` is explicitly visible at the end of the query:

{% image
   source="https://datadog-docs.imgix.net/images/dashboards/functions/rollup/as_count_dropdown.e2c8039094682544b45344e5e5c5a6b2.png?auto=format"
   alt="as_count" /%}

For more details about how to use `.as_count()` and `.as_rate()` see the [Visualize StatsD metrics](https://www.datadoghq.com/blog/visualize-statsd-metrics-counts-graphing) blog post, or learn more about the effects of those functions with the documentation on [in-application modifiers](https://docs.datadoghq.com/metrics/custom_metrics/type_modifiers/).

## Rollup with calendar-aligned queries{% #rollup-with-calendar-aligned-queries %}

{% image
   source="https://datadog-docs.imgix.net/images/dashboards/functions/rollup/calendar_aligned_queries.f13092180441bb0055bbdae428a498cd.png?auto=format"
   alt="calendar_aligned_queries" /%}

You can customize how your metrics data is bucketed over time when using the `.rollup()` function with calendar-aligned queries. This feature allows you the flexibility to define:

- Calendar-aligned monthly queries with adjustable start date and timezones. For example, you can compare your monthly client errors for February and December of last year.
- Weekly rollups with adjustable start date and timezones. For example, see how many weekly transactions are open (if your week starts on Mondays).
- Daily rollups with adjustable start time and timezones. For example, see how many events of interest occurred on the current day (if your day begins at midnight Pacific Time).

## Rollups in monitors{% #rollups-in-monitors %}

Rollups should usually be avoided in monitor queries, because of the possibility of misalignment between the rollup interval and the evaluation window of the monitor. The start and end of rollup intervals are aligned to UNIX time, not to the start and end of monitor queries. Therefore, a monitor may evaluate (and trigger on) an incomplete rollup interval containing only a small sample of data. To avoid this issue, delay the evaluation of your monitor by (at least) the length of the setup rollup interval.

If your monitor queries are unexpectedly showing "No Data", consider reviewing your settings for rollups and evaluation windows. For more information, see [Troubleshooting No Data in Monitors](https://docs.datadoghq.com/monitors/guide/troubleshooting-no-data/).

## Further reading{% #further-reading %}

- [Understanding rollup function and cardinality in visualizations](https://docs.datadoghq.com/dashboards/guide/rollup-cardinality-visualizations)
