Group By
Group by is the setting that splits an aggregation by the value of a tag or attribute, creating as many lines or rows as there are distinct values. In Datadog it appears in metric graphs, log analytics, and monitors alike, but how things are counted after splitting differs in each.
Overview
Without it, the collected values are folded into a single line or a single number, and the breakdown is not visible. Choosing a tag such as host or service splits the values, so you can compare side by side which host is heavy or which service has many errors. It is the concept to keep in mind when you want to count things grouped by item, when the counts of the groups do not add up to the total, and when only some of the values appear in a chart. Grouping by day or by week belongs to time aggregation and is decided separately from group by.
Regrouping values at the same moment by tag value
In a metric graph, you choose how to combine into a line the values that arrive at the same moment from many hosts or instances. The tag you choose next to the aggregation method is the unit that splits the lines. Choosing host creates one line per host, and each line is that host's values aggregated with the chosen method. Clicking a tag listed in the metric selection field also lets you use it as the unit for split aggregation (as of October 2026; Source: Querying). The official documentation calls this space aggregation and distinguishes it from time aggregation, which combines points over time intervals. Counting things grouped by day belongs to the time side and is left to the explanation in Rollup.
Metrics and logs count differently after splitting
Metric graphs and log analytics follow different rules on three points: the unit of splitting, the value produced within each split, and how formulas are built.
| Rule | Metric graphs | Log analytics |
|---|---|---|
| Unit of splitting | The tag chosen next to the aggregation method (with host, one line per host) | A group for each search value of the query |
| Value produced within each split | The value of the chosen aggregation method (default avg by; also max by / min by / sum by) | Count / number of distinct values (count unique of) / numeric minimum, maximum, average, percentile |
| Building multiple queries into a formula | Queries are assigned letters a, b, and you write something like a / b in the formula field | Group all queries by the same search value |
For metrics, combining all hosts into one line with the default gives an average line, and when you want to see the total count you need to change it to sum by. When you want to layer another level of aggregation on top of the split results, Nested Queries let you add time or space aggregation to the results of an existing query (as of October 2026; Source: Querying). What to watch for with logs is when a single log has multiple values. A log that has both team:sre and team:marketplace is counted once in each of the two groups (as of October 2026; Source: Log Analytics). This overlap is why adding up the group counts gives more than the total.
Only the top values appear in a log chart
Group by in log and event queries has limit, which decides the number of groups returned, and sort, which sets the order (as of October 2026; Source: Timeseries Widget). Values beyond that number do not appear in the chart, so the more distinct values the tag you split by has, the more values become invisible. How the number of distinct values also affects the volume sent is summarized in Cardinality. In log analytics, the Top List chart splits by only one dimension, while timeseries, tables, treemaps, and pie charts can stack dimensions. When stacked, the top values are chosen in sequence.
- Choose the top values in the first dimension
- Within the chosen values, choose the top values in the second dimension
- Within those, choose the top values in the third dimension
Even a value with a high count in the second dimension does not appear in the table if its value in the first dimension is not in the top. This is why swapping the order of splitting changes the results. Changing the legend order with Sorting in a timeseries chart changes only the appearance and does not affect the query, so how the top values are chosen stays the same (as of October 2026; Source: Timeseries Widget).
Splitting in a monitor changes the unit of notification
When you use the same setting in a monitor, what gets split is not the lines of a chart but the unit of evaluation and notification; how that works and how to choose are summarized in the explanation in Monitor.
Check whether the sum of the breakdown matches the overall line
Whether you can trust the numbers in a split chart is easier to confirm by putting it next to an unsplit chart. Here, the recommended comparison is to duplicate the grouped chart and remove group by only on the duplicate, making it a single overall line. For metrics, whether the sum of the lines matches the overall line tells you whether the aggregation method has been left at avg by. For logs, when the total of the group counts exceeds the overall count, you can suspect logs with multiple values or overlapping Attribute values. Comparing the number of distinct values of the same field (count unique of) with the number of groups in the chart also tells you whether some values were hidden by the top cutoff. When they do not match, change only one of the aggregation method or the tag you split by, and see whether the sum of the breakdown gets closer to the overall line.