# Node-red / grafana sum/average

**URL:** <https://discourse.nodered.org/t/node-red-grafana-sum-average/48999>\
**Category:** General\
**Created:** [28 July 2021 07:46 UTC](https://discourse.nodered.org/t/node-red-grafana-sum-average/48999 "2021-07-28T07:46:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trombose009](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trombose009/32/30787_2.png) [@trombose009](https://discourse.nodered.org/u/trombose009)\
**Post date:** [28 July 2021 07:46 UTC](https://discourse.nodered.org/t/node-red-grafana-sum-average/48999/1 "2021-07-28T07:46:50Z")

</div>

Hello,

following situation:  
I have some solar panels and using some esp32 stuff, I got a value every 30 minutes which represents the average of the generated power during the last 30 minutes time period.  
Hopefully you understand what I mean. 🙂  
So for example in a time range from 8-10 o'clock, I get 4 values, e.g.:  
8:30: 150W  
9:00: 230W  
9:30: 170W  
10:00: 50W

These are the values, which are permanently written into my InfluxDB and with which I have to deal with.  
So that means, if I sum up these values (600W) and divide them through the time, I should get 300Wh.

My goal sounds pretty easy. I want to display just the value of all Wh which my solar panels have collected. So I have to do some calculation in a grafana query, I think. Or not?

The result do not have to show a specific time period (it could, but it do not need to). I am interested in the sum of every generated Wh during the whole year.

Can anyone help me or do I have to go to a grafana forum?

Greetings

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 July 2021 08:15 UTC](https://discourse.nodered.org/t/node-red-grafana-sum-average/48999/2 "2021-07-28T08:15:39Z")

</div>

> [@trombose009](#):
>
> The result do not have to show a specific time period (it could, but it do not need to). I am interested in the sum of every generated Wh during the whole year.

Just starting work so time is limited but ...

I think that you need to select the whole year as a fixed time selection (rather than Grafana's normal sliding time window) and then group by year. Using the sum and avg functions should then give you the answers.

Because this is rather different to a normal Grafana query, it might actually be easier to try things out in the InfluxDB command line. There are some examples on the InfluxDB docs site.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 July 2021 09:45 UTC](https://discourse.nodered.org/t/node-red-grafana-sum-average/48999/3 "2021-07-28T09:45:26Z")

</div>

Do you want to do this in Grafana or in a direct query on the database?

Edit:  
If you want a direct query to give you the total Wh over a period then it will be something like  
`SELECT SUM("value")/2 FROM "the_measurement" WHERE ...`  
with a WHERE clause selecting the time range.  
The divide by 2 is because, for example, the value 150W at 08:30 is 75Wh, the 230W at 09:00 is 115Wh and so on, so you just have to add them up over the total time range and divide by 2.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 September 2021 09:45 UTC](https://discourse.nodered.org/t/node-red-grafana-sum-average/48999/4 "2021-09-26T09:45:39Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
