# Subtract to values in Grafana

**URL:** <https://community.grafana.com/t/subtract-to-values-in-grafana/1045>\
**Category:** Grafana\
**Created:** [May 23, 2017, 1:33am UTC](https://community.grafana.com/t/subtract-to-values-in-grafana/1045 "2017-05-23T01:33:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamalli](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@adamalli](https://community.grafana.com/u/adamalli)\
**Post date:** [May 23, 2017, 1:33am UTC](https://community.grafana.com/t/subtract-to-values-in-grafana/1045/1 "2017-05-23T01:33:53Z")

</div>

I am new to grafana and writing queries and need some help. I would like to setup a graph that subtracts two values. I am not very familiar with query language so that is where I am struggling.

What I want to do is subtract

`SELECT mean("value") FROM "Home" WHERE "topic" = '/house/power/solar' AND $timeFilter GROUP BY time(1m) fill(null)`

from

`SELECT mean("value") FROM "Home" WHERE "topic" = '/house/power/main' AND $timeFilter GROUP BY time(1m) fill(null)`

Basically I am trying to get my actual power usage.

I am using influxdb v1.2 and my data is setup as shown below.

`time host topic value 2017-05-17T01:31:49.303162625Z	"AllingtonServ"	"/house/power/main"	2323.419 2017-05-17T01:32:20.30254561Z "AllingtonServ" "/house/power/main"	2304 2017-05-17T01:32:51.308210601Z	"AllingtonServ"	"/house/power/main"	2322.935 2017-05-17T01:31:49.303162625Z	"AllingtonServ"	"/house/power/solar"	-1250 2017-05-17T01:32:20.30254561Z "AllingtonServ" "/house/power/solar"	-1240 2017-05-17T01:32:51.308210601Z	"AllingtonServ"	"/house/power/solar"	-1238`

---

<div class="post-metadata">

**Author:** ![torkel](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/torkel/32/20_2.png) [@torkel](https://community.grafana.com/u/torkel)\
**Post date:** [May 23, 2017, 4:31am UTC](https://community.grafana.com/t/subtract-to-values-in-grafana/1045/2 "2017-05-23T04:31:40Z")

</div>

Not sure InfluxDB query language can do that

---

<div class="post-metadata">

**Author:** ![daniellee](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/daniellee/32/41_2.png) [@daniellee](https://community.grafana.com/u/daniellee)\
**Post date:** [May 23, 2017, 8:12am UTC](https://community.grafana.com/t/subtract-to-values-in-grafana/1045/3 "2017-05-23T08:12:56Z")

</div>

This might give you some hints on how to use subqueries in InfluxDB (they were introduced recently):

> **[Server availability percentage value](https://community.influxdata.com/t/server-availability-percentage-value/243)**
>
> Hello, I’m very happy with the usability of the TICK stack, but I am missing one very vital feature which is what I’d call a “server availability percentage value”. What I mean with that is, I would like to have an automatically calculated value...

---

<div class="post-metadata">

**Author:** ![anon80964540](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@anon80964540](https://community.grafana.com/u/anon80964540)\
**Post date:** [January 13, 2021, 4:02pm UTC](https://community.grafana.com/t/subtract-to-values-in-grafana/1045/4 "2021-01-13T16:02:36Z")

</div>

Closed on January 13, 2021, 4:02pm UTC


