Display difference of (subtracted) 2 series with different timestamps

Dear all, I have 2 measurement series from 2 different sensors and at different timestamps, that I do Grafana charts 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 calculations may be wanted later)

You could used a combination of:

  1. Subqueries, where each of the above is used to pull the respective value in a subquery, and then you do the math in the main query
  2. GROUP BY time(<period>) on each of the subqueries (with an aggregator like mean()), in order to get matching timestamps. The appropriate <period> will depend on the frequency of the respective readings - it should be long enough that each aggregation period contains at least one datapoint. You can also add something like FILL(last), if e.g. one reading is much more frequent than the other.
1 Like

Thank you! From your comment (2) I understood, that it is nesessary to calculate common time stamps, and then do a calculation of every single of it. I have no idea how to proceed with (1) / how you think it :slight_smile:

About the timing, the wetness sensor gives a value quite constant every 2 hours plus/minus some minutes, the temp sensor when the temp changes, generally more frequent about every 20 minutes. So I would like to go back on every temp sensor measurement and subtract it from the “last available” wetness value. Maybe also vice versa to cover also the wetness sensor time stamps.

But how to do in “Influx sql” ?

Hm I may have spoken too soon - maybe it’s indeed not possible to subtract the results of two subqueries (based on a bit of googling I just did)

In recent versions of Grafana it’s possible to do math on separate query results, though, so maybe give that a go? Transformations | Grafana Labs