It would help if you used Absent with labels to convert the value from 1 to zero, use clamp_max

( Metrics{label=“a”} OR clamp_max(absent(notExists{label=“a”}),0))
+
( Metrics2{label=“a”} OR clamp_max(absent(notExists{label=“a”}),0)

Vector(0) has no label.

clamp_max(Absent(notExists{label=“a”},0) is 0 with label.

Answer from user2244652 on Stack Overflow
🌐
Medium
nklya.medium.com › promql-how-to-return-0-instead-of-no-data-9e49f7ccb80d
PromQL / How to return 0 instead of ‘no data’ - Nicolai Antiferov - Medium
October 26, 2025 - And to solve this, you just need to add OR on() vector(0) to the end of your promQL query. It will return 0 if the metric expression does not return anything. Explanation: Prometheus uses label matching in expressions.
Discussions

Query with OR
Why do you need 0 instead of 1? Maybe what you want to achieve with your panel can be done via panel configuration? What comes to mind is 'Value mappings' or maybe even an override? More on reddit.com
🌐 r/PrometheusMonitoring
6
2
August 14, 2023
Show "no data" as 0 with multiple time series
I have some SNMP data in Prometheus that sometimes returns “no data” for the up metric and I want to count those as 0 instead, to visualize in Grafana stat panel. How are you trying to achieve it? For a single time series I can achieve this by adding OR on() vector(0) to the end of the ... More on community.grafana.com
🌐 community.grafana.com
1
1
November 8, 2023
PromQL: additions and subtractions between some vectors and an empty vector result in empty vector
What did you do? I encountered a corner case in a PromQL expression used in an alert where some vector - an empty vector resulted in an empty vector. This may be intended, but it seemed odd as it w... More on github.com
🌐 github.com
2
1
January 25, 2022
database - Prometheus, OR Vector(0) - Stack Overflow
I am trying to run this query in Prometheus. But I need to add "OR Vector(0)" operation, so in case there is no value available (NaN) it will hit a 0. Really appreciate if you can tell me how to u... More on stackoverflow.com
🌐 stackoverflow.com
April 23, 2020
🌐
SigNoz
signoz.io › guides › how to merge zero values with metrics in promql - a guide
How to Merge Zero Values with Metrics in PromQL - A Guide | SigNoz
October 22, 2024 - Alerts that trigger incorrectly: If data collection fails, Prometheus might interpret it as zero usage, triggering false alarms. To address these problems, you need to merge zero values with your existing metrics. This approach fills the gaps, ensuring a complete dataset for reliable analysis and accurate visualizations. PromQL provides the vector(0) function, which generates a constant zero value for every time series that doesn’t have a data point at a particular timestamp.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › 6kFUTfSamLA
Default value of zero when metric is null in a formula
pg_up{cluster="alpha"} / ccp_is_in_recovery_status{cluster="alpha"} OR vector(0) If all nodes are up, it still always returns an extra vector(0) in addition to the normal node values. And if more than one node is down, it only returns one empty value vs having multiples returned.
🌐
Serverless Geek
pgrzesik.com › posts › til-prometheus-default-zero
TIL: Returning 0 instead of null in Prometheus | Serverless Geek
October 2, 2024 - Luckily, there's a nice way of defaulting to 0 instead of null! In order to do that, you can use OR on() vector(0) after the possibly null-ish part of the query. #prometheus #grafana
🌐
Reddit
reddit.com › r/prometheusmonitoring › query with or
r/PrometheusMonitoring on Reddit: Query with OR
August 14, 2023 -

Hello,

I have such a query:

up{name=~"node1|node2|node3"}

Which returns `1` if the node is up, and nothing if it's down or does not exist. The problem is that I'd like to have `0` if the node is down or does not exist. I tried with:

up{name=~"node1|node2|node3"} OR on() vector(0)

But it doesn't work.

The best solution which works is:

(sum by(name) (up{name="node1"}) OR on() vector(0))
OR
(sum by(name) (up{name="node2"}) OR on() vector(0))
OR
(sum by(name) (up{name="node3"}) OR on() vector(0))

But I looking for a solution that allows to use Grafana variable. I want to use $NAMES, e.g.:

up{name=~"$NAMES"}

Having the above long solution does not allow to do it.It is worth noting that I don't have access to the Prometheus instance. It's out of my control. I have only Grafana which uses Prometheus as a data source.

Do you have some idea how to do it in one query?

PS. To be honest, I didn't know what title should I choose.

--- EDIT (SOLUTION) ---

I've resolved my problem using the following query:

(sum by (name) (up{name='node1'}) OR clamp_max(absent(up{name='node1'}),0))
OR
(sum by (name) (up{name='node2'}) OR clamp_max(absent(up{name='node2'}),0))
OR
(sum by (name) (up{name='node3'}) OR clamp_max(absent(up{name='node3'}),0))
OR
(sum by (name) (up{name='node4'}) OR clamp_max(absent(up{name='node4'}),0))
OR
(sum by (name) (up{name='node5'}) OR clamp_max(absent(up{name='node5'}),0))

Each node has 1 query containing 2 parts. The first part `sum by (name) (up{name='node1'})` returns the sum of number 1 (`up` result). The second part (`clamp_max(absent(up{name='node1'}),0)`) returns zeros even if the metric for a node has disappeared (eg. because of no data or the target does not exist).

Between all queries is `OR`. As a result, I have a graph showing 0 or 1 for each node, even if a node has no data or is not available (then there is 0).

Disadvantage - I have to update that query each time a node will be removed or added to my system.

🌐
Google Groups
groups.google.com › g › prometheus-users › c › 4sD0nyRcS-w
Null value in alerts
PromQL expressions don't work like normal boolean expressions. They return the presence or absence of values, not a true or false value. The presence of *any* value will trigger an alert, and vector(0) generates a value all of the time.
🌐
Grafana
community.grafana.com › prometheus
Show "no data" as 0 with multiple time series - Prometheus - Grafana Labs Community Forums
November 8, 2023 - I have some SNMP data in Prometheus that sometimes returns “no data” for the up metric and I want to count those as 0 instead, to visualize in Grafana stat panel. How are you trying to achieve it? For a single time series I can achieve this by adding OR on() vector(0) to the end of the ...
Find elsewhere
🌐
SigNoz
signoz.io › guides › how to handle null values in prometheus time series data
How to Handle Null Values in Prometheus Time Series Data | SigNoz
October 14, 2024 - group_left: Matches system_res... resource usage data is missing for some instances. or vector(0): Fills missing values with 0 for better visualization....
🌐
Stack Overflow
stackoverflow.com › questions › 61383545 › prometheus-or-vector0
database - Prometheus, OR Vector(0) - Stack Overflow
April 23, 2020 - I am trying to run this query in Prometheus. But I need to add "OR Vector(0)" operation, so in case there is no value available (NaN) it will hit a 0. Really appreciate if you can tell me how to u...
Author: grafana
🌐
GitHub
github.com › VictoriaMetrics › VictoriaMetrics › issues › 7640
Query with "or on() vector(0)" return an extra data series · Issue #7640 · VictoriaMetrics/VictoriaMetrics
November 25, 2024 - When query like this up{job="apiserver"} or on() vector(0), vm returns an extra data series that was not within my expect. Its has a data series which value is 0 and has no labels, but I think the or on() vector(0) is only used for the up{job="apiserver"} has no value.
Author: VictoriaMetrics
🌐
GitHub
github.com › grafana › grafana › issues › 59349
Prometheus query expression 0/0 and 1-0/0 returns 0 · Issue #59349 · grafana/grafana
November 27, 2022 - 1 - (( sum(rate(http_server_sli_total{app="myapp", sli_error_type="service_error"}[1m])) / sum(rate(http_server_sli_total{app="myapp"}[1m])) > 0 ) or on() vector(0)) otherwise the SLI ends up showing zero during zero traffic scenarios. In prometheus, when omitting the > 0 the query does not return a value.
Author: grafana
🌐
Grafana
community.grafana.com › prometheus
PromQL won't handle null values during vector matching - Prometheus - Grafana Labs Community Forums
March 18, 2021 - Hi. I have two PromQL queries in Grafana. Query 1: max_over_time(counter{label="label1"}[5m]) Query 2: max_over_time(counter{label="label1"}[5m] offset 10m) There’s an exact match between the labels in both queries, …
🌐
GitHub
github.com › grafana › loki › issues › 8266
Not able to add labels to vector from scalar value · Issue #8266 · grafana/loki
January 24, 2023 - sum( count_over_time({project="acme", namespace="prod", "app_kubernetes_io_name"="zero-service"} |= `"level":"warn"`[5m]) or label_replace(vector(0), "app_kubernetes_io_name", "zero-service", "", "") ) by(app_kubernetes_io_name)
Author: grafana
🌐
FOSS TechNix
fosstechnix.com › home › vectors in prometheus with examples
Vectors in Prometheus with Examples
February 18, 2024 - Cannot: Cannot show trends over ... or not (0). You can directly select a metric name to get an instant vector. Use label selectors to filter specific time series within the vector. PromQL functions like count(), min(), max(), etc., can be applied to instant vectors for aggregation. Examples: http_requests_total, up. prometheus_http_requ...
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
This function only works when used directly on an instant vector and when use-start-timestamps feature flag is enabled. Otherwise, if it's used on an expression or if use-start-timestamps is disabled, it returns empty results. This function has to be enabled via the feature flag --enable-feature=promql-experimental-functions. step() returns the query resolution step as the number of seconds. For instant queries, this returns 0...
🌐
pint
cloudflare.github.io › pint › checks › promql › series.html
promql/series | pint
my_metric metric was ever present ... in ... or vector(0) won’t be checked, since the intention of adding or vector(0) is to provide a fallback value when there are no matching time series....