As described in my post on prometheus-developers, here is a possible option, although it's far from readable:

up{job="prometheus"} + ignoring(year, month, day) group_right
  count_values without() ("year", year(timestamp(
    count_values without() ("month", month(timestamp(
      count_values without() ("day", day_of_month(timestamp(
        up{job="prometheus"}
      )))
    )))
  ))) * 0

Replace both instances of up{job="prometheus"} with whatever series selector you need. No idea how efficient this is, though. :o)

Answer from Alin Sînpălean on Stack Overflow
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
Go get our self-paced in-depth PromQL training! Select latest sample for series with a given metric name: ... Available aggregation operators: sum(), min(), max(), avg(), stddev(), stdvar(), count(), count_values(), group(), bottomk(), topk(), quantile() ... Only keep series from the left-hand side whose sample values are larger than their right-hand-side matches: ... histogram_quantile( 0.9, sum by(le, path, method) ( rate(demo_api_request_duration_seconds_bucket[5m]) ) )
🌐
Google Groups
groups.google.com › g › prometheus-developers › c › pul4HF4OS0E
Is it possible to sum a metric by day?
For example, sum up all values for the last 7 days and display one sum for each day. The closest I've gotten is using "increase(mycounter[1d])" and set my min step in grafana to 1d, but this seems to give me 24h behind the current time, and then 24hrs beyond that etc.... whereas I need the midnight to midnight sum. ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... PromQL is a sliding-window query engine that doesn't understand much about such types of alignments.
People also ask

How to use group by in PromQL?
Place the by clause after an aggregation function like sum(), avg(), or count(). For example: sum(http_requests_total) by (service, region) This aggregates the metric and groups results by service and region.
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
How do I use the "group by" function with labels in Prometheus queries?
Apply by (label) after an aggregation function. For example: avg(cpu_usage_seconds_total) by (service) This gives the average CPU usage grouped by service.
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
How can I group labels in a Prometheus query?
Use by (label1, label2) to retain specific labels or without (label) to exclude one or more. For example: sum(cpu_usage) by (region) sum(memory_usage) without (instance)
🌐
last9.io
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for ...
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
Assuming that the http_requests_total time series all have the labels job (fanout by job name) and instance (fanout by instance of the job), we might want to sum over the rate of all instances, so we get fewer output time series, but still preserve the job dimension:
🌐
Medium
medium.com › @suchitasharma1106 › a-comprehensive-guide-to-grouping-and-functions-in-promql-cc3c438be320
A Comprehensive Guide to Grouping and Functions in PromQL | by Suchita Sharma | Medium
October 7, 2024 - Grouping in PromQL helps in aggregating data across multiple dimensions. It allows you to summarize or categorize metrics based on their labels. There are two types of grouping: Without Grouping (without()): Removes certain labels from the ...
🌐
Coralogix
coralogix.com › home › promql tutorial: 5 tricks to become a prometheus god
PromQL Tutorial: Basic Concepts & Examples - Coralogix
June 3, 2025 - Aggregation is a great way to construct powerful PromQL queries. If you’re familiar with SQL, you’ll remember that GROUP BY allows you to group results by a field (e.g country or city) and apply an aggregate function, such as AVG() or COUNT(), to values of another field.
🌐
O11y
o11y.eu › blog › oy-periodic-queries
How To Query Prometheus within calendar boundaries
February 22, 2023 - As you can see, the rules file defines a single group called “prometheus network usage” that specifies a monthly time period and a 365-day lookback. The group contains two rules that calculate the monthly network receive and transmit bytes ...
Find elsewhere
🌐
Last9
last9.io › blog › prometheus-group-by-label
Prometheus Group By Label: Advanced Aggregation Techniques for Monitoring | Last9
June 12, 2026 - How to use group by in PromQL? Place the by clause after an aggregation function like sum(), avg(), or count().
🌐
Medium
valyala.medium.com › promql-tutorial-for-beginners-9ab455142085
PromQL tutorial for beginners and humans | by Aliaksandr Valialkin | Medium
September 15, 2023 - SELECT ts.metric_name_plus_tags, r.timestamps, r.values FROM ( (SELECT time_series_id, array_agg(timestamp ORDER BY timestamp) AS timestamps, array_agg(value ORDER BY timestamp) AS values FROM metrics WHERE time_series_id IN ( SELECT id FROM time_series WHERE metric_name = 'node_network_receive_bytes_total' ) GROUP BY time_series_id ) ) AS r JOIN time_series AS ts ON (r.time_series_id = ts.id) Easy, isn’t it? :) The SQL must be even more complex in order to be on par with the one-word PromQL query above, since it doesn’t take into account time ranges and down-sampling, which are automatically handled by /query_range API for PromQL with start, end and step args.
🌐
Sysrant
sysrant.com › posts › monthly-reports-with-grafana-and-prometheus
Monthly reports with Grafana and Prometheus | Sysrant
July 16, 2021 - 1up{job="prometheus"} + ignoring(year, month, day) group_right 2 count_values without() ("year", year(timestamp( 3 count_values without() ("month", month(timestamp( 4 count_values without() ("day", day_of_month(timestamp( 5 up{job="prometheus"} 6 ))) 7 ))) 8 ))) * 0 · Also there is a really good blogpost (https://www.robustperception.io/monthly-reporting-with-prometheus-and-python), and I'll quote them right now: While PromQL has some calendar functions, it's designed more for doing math over arbitrary fixed time periods rather than time periods that vary over time due to business logic.
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
Please note that sort_by_label only affects the results of instant queries, as range query results always have a fixed output ordering. ... This function has to be enabled via the feature flag --enable-feature=promql-experimental-functions.
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › basics
Querying basics | Prometheus
Other programs can fetch the result of a PromQL expression via the HTTP API. This document is a Prometheus basic language reference. For learning, it may be easier to start with a couple of examples. The value of a sample at a given timestamp returned by PromQL may be a float or a native histogram.
🌐
Logz.io
logz.io › home › blog › how to › an intro to promql: basic concepts & examples
An Intro to PromQL: Basic Concepts & Examples | Logz.io
September 2, 2023 - Similarly, PromQL lets you group multiple labels together, then sorting according to those groupings. If you want a more thorough intro to installation and configuration, check out our recent Prometheus tutorial for system and Docker metrics. To be clear, there are two kinds of “types” in Prometheus. There are the metric types of metrics and the data types of PromQL expressions.
🌐
Last9
last9.io › blog › promql-cheat-sheet
PromQL Cheat Sheet: Queries, Functions, and Labels | Last9
September 12, 2024 - PromQL cheat sheet: quick diagnostic queries, aggregation functions, label filtering, SLO tracking, capacity planning, and multi-cluster patterns for Prometheus monitoring.
Top answer
1 of 1
4

You need to use increase() function for calculating bytes usage over the last 24 hours:

increase(bytes_total_incoming[24h])

This query is executed independently per each point on the graph and per each matching time series. So every point on the graph shows bytes usage for the last 24 hours ending at that point. If you need showing per-day bytes usage on the graph, then the following options exist:

  • To set min interval in Grafana graph panel settings to 24h. See these docs. In this case Grafana would query only a single point per day per each matching time series. Every point will show bytes usage over the previous day ending at the point.
  • To use subquery feature in Prometheus in order to limit increase() calculations to per-day boundaries:
last_over_time(
  increase(bytes_total_incoming[1d])[2d:1d]
)

This query returns a graph with per-day steps showing bytes usage over the previois day.

If you need grouping the results by a paricular label such as car_name or type, then just wrap the query into sum(...) by (car_name) or sum(...) by (type). For example, the following query returns per-day bytes usage grouped by type:

sum(
  increase(bytes_total_incoming[24h])
) by (type)

Tye sum() is an aggregate function, which sums series values individually per each point and groups the reaulting sums by label values specified in the optional by (...) modifier.

P.s. the above queries return per-day bytes usage shifted by one day in the future. For example, they return bytes usage for August 10 at August 11. This shift can be removed with negative offset modifier:

sum(
  increase(bytes_total_incoming[24h] offset -24h)
)

P.p.s. increase() function in Prometheus may return fractional results when applied to integer counters. This is because of extrapolation - see this issue. If you want obtaining the exact increase over integer counter, then try the project I work on - VictoriaMetrics. It implements increase() function in the expected way without using extrapolation. See this article for details.

🌐
SigNoz
signoz.io › guides › how to query data by time period - a step-by-step guide
How to Query Data by Time Period - A Step-by-Step Guide | SigNoz
November 20, 2024 - Time Function: rate() — Calculates the request rate over the last five minutes, giving insights into traffic patterns. Grouping: by (status_code) — Breaks down request counts by HTTP status codes, allowing you to monitor specific response types ...
🌐
Better Stack
betterstack.com › community › questions › how-can-group-labels-in-prometheus-query
How Can I Group Labels in a Prometheus Query? | Better Stack Community
August 5, 2025 - Grouping labels in a Prometheus ... across different dimensions. You can use the by clause in Prometheus Query Language (PromQL) to group your results according to one or more labels....
🌐
VictoriaMetrics
docs.victoriametrics.com › metricsql
VictoriaMetrics: MetricsQL
This function is supported by PromQL. See also day_of_week and day_of_year .
🌐
Grafana
community.grafana.com › prometheus
Count and group by day based on label value - Prometheus - Grafana Labs Community Forums
March 30, 2023 - What Grafana version and what operating system are you using? Grafana v9.1.4 What are you trying to achieve? I’m collecting metrics about log files with filestat_exporter, and i would like to have graphic with the count of rotated logs per day based on values of the label path. file_stat_size_bytes{fqdn=~“$fqdn”,path=~“/var/log/mylog-[0-9].*.log”} so the path label has values like this: /var/log/mylog-2023-03-18.0.log /var/log/mylog-2023-03-18.1.log /var/log/mylog-2023-03-18.2.log ...