# Calculate and display monthly Watt production

**URL:** <https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655>\
**Category:** InfluxDB 2\
**Tags:** influxdb, grafana\
**Created:** [December 7, 2022, 1:22pm UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655 "2022-12-07T13:22:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon91072666](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@anon91072666](https://community.influxdata.com/u/anon91072666)\
**Post date:** [December 7, 2022, 1:22pm UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/1 "2022-12-07T13:22:50Z")

</div>

I would like to get the value of produced Watts of each month.  
Unfortunately, I go get the value of the second month, but the value of the first month is missing.  
In November it was 17.9 kwh in October it was 300wh but all I see is 300wh in October.

My current query is:

> from(bucket: “XX”)  
> |\> range(start: -11mo)  
> |\> filter(fn: (r) =\> r[“\_measurement”] == “XXXXXXXXXXX”)  
> |\> filter(fn: (r) =\> r[“\_field”] == “pvenergytotal”)  
> |\> toFloat()  
> |\> map(fn: (r) =\> ({r with \_value: r.\_value / 10.0}))  
> |\> aggregateWindow(every: 1mo, offset: -2h1m, fn: last)  
> |\> difference()

With “difference()” at the end:

 ![pvenergy1](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/4/4efa95d5e5a3d6b9a55ff03eb305c6eb1c7223b1.png)

Any idea how I get the value of November as well?

---

<div class="post-metadata">

**Author:** ![anon91072666](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@anon91072666](https://community.influxdata.com/u/anon91072666)\
**Post date:** [December 7, 2022, 1:23pm UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/2 "2022-12-07T13:23:28Z")

</div>

…And here without “difference()” at the end:

 ![pvenergy2](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/d/d41eb45e961ebb61030dbf9ecf9e0b880081be8b.png)

---

<div class="post-metadata">

**Author:** ![grant1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/grant1/32/15107_2.png) [@grant1](https://community.influxdata.com/u/grant1)\
**Post date:** [December 8, 2022, 2:11am UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/3 "2022-12-08T02:11:26Z")

</div>

I think your question may be more of a Grafana question, but since this is the InfluxDB forum, I thought I would share some data & queries that may be helpful.

I collected my kWh every hour from January thru August (8 months, or 243 days)

Here is the data by hour (5832 points on the graph, or 243 x 24)

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/1/1dcb95374dc0178a14170342ae25cee11b94e586.png)

Here is the data by day (243 points on the graph)

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/7/77d158022a741e28ad00f8dc85e4237b9552f0d5.png)

Here is the data by month (8 points on the graph):

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/b/ba6bb047ff6229b77d3670a90c383e3ad8b1aa12.png)

Note that I am aggregating the data differently in each of the above. I am using the fn: mean to collect the arithmetic average of the hourly values collected (the average of 24 readings in the 1d aggregateWindow, and the average of all hourly readings during the month in the 1mo aggregateWindow).

Questions for you:

1. What does your query look like in Influx Data Explorer?
2. Why do you have the range `|> range(start: -11mo)` ?
3. Why do you have the `difference()` function?

---

<div class="post-metadata">

**Author:** ![anon91072666](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@anon91072666](https://community.influxdata.com/u/anon91072666)\
**Post date:** [December 8, 2022, 8:14am UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/4 "2022-12-08T08:14:31Z")

</div>

You are absolutely right, sorry for sharing a Grafana Screenshot. The result is the same for Influx.  
I have two values. One that I could use is the daily produced kwh (pvenergytoday), In my case I used pvenergytotal which stores the total value of produced kwh from day 1 on.

Why do I use the difference() function?  
With my query I try to get the pvenergytotal per month and calculate the difference of each time sequence sequence (here one month).  
So in October I’ve had none (NULL), in November I’ve had 17,9kwh and in December I’ve had 300kwh so far.  
As October is NULL I would expect that the difference to November is 17.9kwh and the next difference to 18.2kwh in December is 300wh, which I can see in the graph. But I don’t see the 17.9kwh in November.

Another attempt could be to sum up all daily values of a month (pvenergytoday) and display them for each month.

Why do I use the range of

> |\> range(start: -11mo) ?

This is because I would like to see the produced kwh of each month on comparison to the other months and 11 month back in the past.

My Query with (differernce()) in Influx:

 ![pvenergy3](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/b/b5c889ff085dc9bb1b7955f9fd0192e11361ebb4.png)

---

<div class="post-metadata">

**Author:** ![anon91072666](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@anon91072666](https://community.influxdata.com/u/anon91072666)\
**Post date:** [December 8, 2022, 8:15am UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/5 "2022-12-08T08:15:23Z")

</div>

And the request with yield() (which as far as I know is assumed in each query anyhow, even if you dont write it down):

 ![pvenergy4](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/5/55bfe0da57555e7e743d65d9df9e24d4f4c57443.png)

---

<div class="post-metadata">

**Author:** ![grant1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/grant1/32/15107_2.png) [@grant1](https://community.influxdata.com/u/grant1)\
**Post date:** [December 8, 2022, 10:31am UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/6 "2022-12-08T10:31:20Z")

</div>

What happens if you change the `aggregateWindow` function to `fn: sum`?

```auto
from(bucket: “XX”)
|> range(start: -11mo)
|> filter(fn: (r) => r[“_measurement”] == “XXXXXXXXXXX”)
|> filter(fn: (r) => r[“_field”] == “pvenergytotal”)
|> toFloat()
|> map(fn: (r) => ({r with _value: r._value / 10.0}))
|> aggregateWindow(every: 1mo, offset: -2h1m, fn: sum)
|> difference()

```

---

<div class="post-metadata">

**Author:** ![anon91072666](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@anon91072666](https://community.influxdata.com/u/anon91072666)\
**Post date:** [December 8, 2022, 10:43am UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/7 "2022-12-08T10:43:52Z")

</div>

This example returns -14900 as a value of December and still no value for November.

---

<div class="post-metadata">

**Author:** ![anon91072666](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@anon91072666](https://community.influxdata.com/u/anon91072666)\
**Post date:** [December 19, 2022, 9:14am UTC](https://community.influxdata.com/t/calculate-and-display-monthly-watt-production/27655/8 "2022-12-19T09:14:54Z")

</div>

Anyone who is able to help me?
