The Subquery is what you need indeed (credit to commenter above M. Doubez). This should work for you - it calculates the weekly delta by calculating the subquery each day (see [1w:1d])

delta(label_replace({__name__=~"desired_metric_prefix_.+_suffix"}, "metric_name", "$1", "__name__", "desired_metric_prefix_(.+)_suffix")[1w:1d])

Be sure that all of the metrics that match your regex are compatible with the label_replace and with the delta functions. If you're displaying this in Grafana, use Legend expression {{ metric_name }} to display the extracted metric_name for each series.

Answer from Steve Jones on Stack Overflow
Top answer
1 of 2
9

The Subquery is what you need indeed (credit to commenter above M. Doubez). This should work for you - it calculates the weekly delta by calculating the subquery each day (see [1w:1d])

delta(label_replace({__name__=~"desired_metric_prefix_.+_suffix"}, "metric_name", "$1", "__name__", "desired_metric_prefix_(.+)_suffix")[1w:1d])

Be sure that all of the metrics that match your regex are compatible with the label_replace and with the delta functions. If you're displaying this in Grafana, use Legend expression {{ metric_name }} to display the extracted metric_name for each series.

2 of 2
8

The {__name__=~"taskcnt.*"} may return multiple time series with identical set of labels, but with different metric names. For example, it may return the following time series:

taskcnt_foo{job="x",instance="y"}
taskcnt_bar{job="x",instance="y"}

As you can see, these time series have identical set of labels - {job="x",instance="y"}, while they have different metric names: taskcnt_foo vs taskcnt_bar.

The delta() function strips metric names from results, so it strips taskcnt_foo and taskcnt_bar names from the original time series and returns two time series with identical labelset - {job="x",instance="y"} when {__name__=~"taskcnt.*"} series selector is passed to it. This results in vector cannot contain metrics with the same labelset error, since the returned time series cannot be differentiated from each other.

Unfortunately Prometheus doesn't allow to use label_replace() or any other function inside delta()-like functions, which accept e.g. range vector - a series selector ending with square brackets (for example, {__name__=~"taskcnt.*"}[1w]).

There is a half-working solution by using subqueries, which is recommended in this answer. Unfortunately this solution has the following drawbacks:

  • Prometheus subqueries may take significant amounts of additional CPU, memory and disk IO during execution, especially if the interval value is too small compared to the lookbehind window in square brackets: [window:interval].
  • Prometheus subqueries may miss original raw data during calculations when the interval in square brackets is too big.
  • Prometheus subqueries are easy to mis-use if their behavior isn't understood clearly.

These issues are addressed by VictoriaMetrics in MetricsQL with keep_metric_names modifier, which can be applied to any function. For example, the following MetricsQL query doesn't strip metric names from results, so it doesn't return neither vector cannot contain metrics with the same labelset nor ranges only allowed for vector selectors errors:

increase({__name__=~"taskcnt.*"}[1w]) keep_metric_names
🌐
Grafana
community.grafana.com › prometheus
Calculation within aggregation function - Prometheus - Grafana Labs Community Forums
November 28, 2024 - On Grafana Cloud, the following expression evaluates fine: max_over_time(series_xy{label_a="A"} [1h]) but this one breaks: max_over_time((series_xy{label_a="A"}) [1h]) What I was trying to do is perform a calculation and then max_over_time the result. This is apparently not working.
🌐
OneUptime
oneuptime.com › home › blog › how to fix 'ranges only allowed for vector selectors' errors
How to Fix 'ranges only allowed for vector selectors' Errors
December 17, 2025 - Prometheus tells you that [5m] (a range) can only be applied to a simple vector selector like metric_name{labels}, not to an expression result. flowchart TD subgraph "Valid" A[metric_name] --> B["metric_name[5m]"] C["metric_name{job='api'}"] ...
🌐
Reddit
reddit.com › r/prometheusmonitoring › instant vectors to ranged vectors
r/PrometheusMonitoring on Reddit: Instant vectors to ranged vectors
March 5, 2022 -

Why doesn’t ”(some_metric*10)[1h]” work? When i try it i get error: ”ranges only allowed for vector selectors”.

Wouldnt a instant vector and a scalar together return another instant vector that can be turned into a ranged vector?

Im very very stuck pls help

🌐
SigNoz
signoz.io › guides › how to create range vectors in prometheus queries
How to Create Range Vectors in Prometheus Queries | SigNoz
November 20, 2024 - Range vectors in Prometheus allow you to analyze metric data over specific time periods. You create range vectors by adding a time duration selector [d] to your instant vector selectors. This fundamental concept enables you to perform time-series analysis, calculate rates of change, and identify trends in your metrics data. Range vectors are a crucial concept in Prometheus for ...
🌐
GitHub
github.com › prometheus › prometheus › issues › 1227
Sub query support for range selection. · Issue #1227 · prometheus/prometheus
November 18, 2015 - Currently one can only do range selection on vector selectors and has to use recording rules to range-select expressions.
Author: prometheus
🌐
Promlabs
promlabs.com › blog › 2020 › 07 › 02 › selecting-data-in-promql
PromLabs | Blog - Selecting Data in PromQL
July 2, 2020 - An instant vector selector allows you to select the latest sample value at every evaluation resolution step of a range query, or in an instant query, at a single evaluation timestamp. It's called a vector selector because it returns a whole set (vector) of series, with one sample for each series (thus an instant vector). To select the latest value for any series with the metric name api_http_requests_total, you simply write the metric name: ... To only select series with the method POST and the handler /api/widgets, you can add some label matchers in curly braces that restrict the output:
🌐
Google Groups
groups.google.com › g › prometheus-developers › c › 9FUIras-Alw
Cannot apply range selectors
The reason is that a graph query ... return an instant vector, like: rate(http_requests_total[5m]). The short rule is that only expressions that return an instant vector can be graphed....
Find elsewhere
🌐
VictoriaMetrics
victoriametrics.com › blog › prometheus monitoring: instant queries and range queries explained
Prometheus Monitoring: Instant Queries and Range Queries Explained
February 21, 2025 - So just to clear things up; expressions like node_cpu_usage and node_cpu_usage{instance="server1"} aren’t queries on their own. They’re just selectors that can be evaluated as either an instant query or a range query. An instant vector is a set of timeseries where each timeseries has only one sample, the most recent value at the time the query runs.
🌐
YouTube
youtube.com › watch
Resolving the ranges only allowed for vector selectors ...
Discover how to fix Prometheus query errors related to vector selectors and calculate delta metrics effectively.---This video is based on the question https:...
Published: July 31, 2025
Views: 2
🌐
VictoriaMetrics
docs.victoriametrics.com › metricsql
VictoriaMetrics: MetricsQL
For example, every point for avg_over_time(temperature[24h]) graph shows the average temperature for the last 24 hours ending at this point. The interval between points is set as step query arg passed by Grafana to /api/v1/query_range . If the given series selector returns multiple time series, then rollups are calculated individually per each returned series.
🌐
W3C
w3.org › TR › selectors-4
Selectors Level 4
Selector logic can be manipulated by compounding (logical AND), selector lists (logical OR), and the logical combination pseudo-classes :is(), :where(), and :not(). The logical combination pseudo-classes are allowed anywhere that any other pseudo-classes are allowed, but pass any restrictions to their arguments. (For example, if only compound selectors are allowed, then only compound selectors are valid within an :is().)
🌐
Rosettacommons
docs.rosettacommons.org › docs › latest › scripting_documentation › RosettaScripts › ResidueSelectors › ResidueSelectors
ResidueSelectors
If "error_on_out_of_bounds_index" ... This behaviour can be disabled by setting "error_on_out_of_bounds_index" to false, which allows the selector to ignore indices that are out of range silently....
🌐
Neo4j
neo4j.com › docs › cypher-manual › current › patterns › reference
Syntax and semantics - Cypher Manual
For example, a path pattern that is a quantified path pattern with a quantifier that has a lower bound of zero is not allowed: ... A path pattern must always begin and end with a node pattern. ... A path pattern may be composed of a concatenation of simple and quantified path patterns. Two simple path patterns, however, may not be placed next to each other. ... When a path pattern is matched to paths in a graph, nodes can be revisited but relationships cannot. A subpath variable (a path variable declared inside a parenthesized path pattern expression) can only be used if a shortest paths mode is also specified.
🌐
BookStack
bookstack.cn › read › prometheus-2.44-en › 51969b2f65dbe0e3.md
Querying - Basics - 《Prometheus v2.44 Documentation》 - 书栈网 · BookStack
October 17, 2023 - Scalar float values can be written as literal integer or floating-point numbers in the format (whitespace only included for better readability): ... Instant vector selectors allow the selection of a set of time series and a single sample value for each at a given timestamp (instant): in the simplest form, only a metric name is specified.
🌐
Minecraft Wiki
minecraft.fandom.com › wiki › Target_selectors
Target selectors – Minecraft Wiki
1 week ago - In Java Edition: [distance=<value>] — Specifies the range of distance. Float ranges are supported to select a specific region. Only unsigned values are allowed.
🌐
Highcharts
highcharts.com › docs › stock › range-selector
Range selector | Highcharts
The range selector is a tool for selecting ranges to display within the chart. It provides buttons to select pre-configured ranges in the chart, like 1 day, 1 week, 1 month, etc. It also provides input boxes where min and max dates can be manually input. The range selector box can be positioned vertically. ... Use the x and y options to customize position. The x and y options offset the selector by pixels from the given alignment. The option allows ...