Display difference of (subtracted) 2 series "on the fly"

Dear all, I have 2 measurement series from 2 different sensors and at different timestamps, that I do Grafana figures from, that works really nice.

Now I would like to “subtract one graph from the other and display the resulting graph” - but how to do?

The graphs I create/fill with this 2 queries:

SELECT “Temperatur” FROM “M41” WHERE (“Sensor” = ‘Beet’) AND $timeFilter

SELECT (“Wetness”) FROM “M41” WHERE (“Sensor” = ‘Feuchte’) AND $timeFilter

As mentioned, the measurements are done continuously, but at different timestamps…

Reason is to somehow “temperature-compensate” the wetness sensor (so other claculations may be wanted later)

Hello @loeten,
I think this would be easier with Flux…but let’s dust off some InfluxQL.

SELECT "T" - "W" FROM (SELECT mean(“Temperatur”) AS "T", mean("Wetness") AS "W" FROM “M41” WHERE (“Sensor” = ‘Beet’) AND AND time >= 'start' AND time <= 'end' GROUP BY time(10m) fill(previous))

I’m using this as a reference:

And I’m grouping by time and applying the mean to get the timestamps to line up. You could use whatever aggregation function you want though.

In Flux you have many more options available to you though…tons of functions to manipulate time with: Query Group by time ( Shift time) - #2 by Anaisdg

Thank you - I see the principle of the subquery. I will play around with it a bit and see, how I can use the typical Grafana “$timeFilter” in it.