# Difference between multiple values in one measurements with InfluxDB

**URL:** <https://community.grafana.com/t/difference-between-multiple-values-in-one-measurements-with-influxdb/42062>\
**Category:** InfluxDB\
**Created:** [January 23, 2021, 1:30pm UTC](https://community.grafana.com/t/difference-between-multiple-values-in-one-measurements-with-influxdb/42062 "2021-01-23T13:30:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dergerhard](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dergerhard](https://community.grafana.com/u/dergerhard)\
**Post date:** [January 23, 2021, 1:30pm UTC](https://community.grafana.com/t/difference-between-multiple-values-in-one-measurements-with-influxdb/42062/1 "2021-01-23T13:30:34Z")

</div>

Hi,

I am currently trying to display difference of results from 2 sensors in a Grafana panel.  
In my InfluxDB database I have a measurement that holds values of both sensors:

```
> SELECT * FROM "Vergleich" WHERE time>now()-2m
name: Vergleich
time rh_dht22 rh_tfa temp_dht22 temp_tfa tp_dht22 tp_tfa
---- -------- ------ ---------- -------- -------- ------
1611407400000000000 45 21.883333333333333 9.40611175608533
1611407433000000000 47 21.3 9.5
1611407460000000000 45 21.833333333333332 9.360802312324173
1611407493000000000 47 21.2 9.4

```

For both sensors (DHT22 and some TFA device) I have stored 3 values each. They are not provided with identical timestamp but that should not be a problem.  
I want to calculate the difference to see how well the various sensors provide similar data.

I am able to get some useful data out of influx:

```
> SELECT mean("temp_dht22") - mean("temp_tfa") AS "d_temp_dht22" FROM "Vergleich" WHERE time>now()-5m GROUP BY time(60s) fill(null)
name: Vergleich
time d_temp_dht22
---- ------------
1611407220000000000
1611407280000000000 -0.6000000000000014
1611407340000000000 -0.6000000000000014
1611407400000000000 -0.5833333333333321
1611407460000000000 -0.6333333333333329
1611407520000000000

```

I got this query string from [Calculate difference between two measurements](https://community.grafana.com/t/calculate-difference-between-two-measurements/16492) and [[VERY NEWBIE] Show difference between two graphs values](https://community.grafana.com/t/very-newbie-show-difference-between-two-graphs-values/29428)

Unfortunately I am not able to add this to my Grafana panel.  
If I add a query and enter this code  
`SELECT mean("temp_dht22") - mean("temp_tfa") AS "d_temp_dht22" FROM "Vergleich" WHERE $timeFilter GROUP BY time($__interval) fill(null)`

it is automatically changed to  
`SELECT "temp_dht22" -, "temp_tfa" AS "d_temp_dht22" FROM "Vergleich" WHERE $timeFilter GROUP BY time($__interval) fill(null)`

and the graph only shows “No data”.

My Grafana version is “v7.3.7 (1e261642f4)” and I run it on a Raspberry 3+ with RaspiOS Buster (Image from 2020-12-02).

Any hints how to insert the query into the fields of my panel is welcome.
