What Grafana version and what operating system are you using?
Grafana v9.5.2 (cfcea75916) on Raspbian
What are you trying to achieve?
I want to sum up a difference between two series, but only the positive values. Background is that I have a energy consumption and a energy production time series, both in InfluxDB. I want to calculate how much I get from the grid (consumption - production, but only positive values).
How are you trying to achieve it?
I created two queries in a dashboard to show the production and the consumption in two lines. I created an expression to calculate the difference. Problem is that both negative and positive values are shown. I want to sum up only the positive values of that expression
Here’s the query for the consumption (A)
SELECT mean("value") FROM "autogen"."sensor.stromzahler_power_curr" WHERE $timeFilter GROUP BY time($__interval) fill(linear)
Production (B)
SELECT mean("value") FROM "autogen"."sensor.power_production_now" WHERE $timeFilter GROUP BY time($__interval) fill(previous)
The difference is created as a Math expression simple as
$A -$B
Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
No errors
The single values are always greater zero, only the difference can be negative.
I understand your queries that it would only filter out the series individual values which are 0 or lower. Am I getting this right?
this is why I do not like using grafana for something that should be done on the server side. grafana is presentation layer. or something like this
declare @power_production_now table(value int)
insert into @power_production_now
select 4 union
select 6
declare @stromzahler_power_curr table(value int)
insert into @stromzahler_power_curr
select 4 union
select 6
---this part below ↓↓↓↓↓↓↓↓↓↓, is it doable in influxql?
select p.value - c.value
from @power_production_now p, @stromzahler_power_curr c
where p.value - c.value > 0
Thank you for all your input! I agree that it would be better to do on the backend. That’s why I’d like to do that in the query instead with visual filters.
What do you mean with “migrate to flux”? Is flux a complete different storage or a different query language?
When I tried this, this filtered also the other series so that everytime the “Netzbezug” is below 0, also power consumption and production where set to 0.
Is it possible to only apply the filter on the expression, instead of both series?