Wrongly calculated "Total" power consumption


I’m trying to build a graph for my house power consumption.
Here is what it looks like (including the queries I’m using):


Just in case it matters, the data comes from a Current Cost Envir device, and represents the current power consumption in Watts.
It is then sent to Home Assistant through MQTT.
Home Assistant writes it into Influxdb, and then Grafana uses this influxdb as data source.

Now, all looks good and reasonable to me apart from the “Totals” in the legend.

For example, the fact that the whole house used 1.3KW on average for the past 6 hours, seems very reasonable.
The “Total” though, displays 2.8MW!?!
I think it should be more something like 7.8KW (the average 1.3KW x 6 hours).

Can anyone help me figuring out what I am doing wrong please?


Your query needs to return the sum for each time interval , the legend values are calculated based on what your query returns. Avg and total cannot be both correct at the same time (if your query contains any aggregation using avg for example).

If you want correct total you need to adjust your query aggregation to sum


Thanks for your quick response.

I am not sure I understood correctly your suggestion.
I changed “mean” to “sum” but the value are still wrong.

Also the max went up to 34.7KW (it should be something like 8/9KW).

Would you be able to describe what I should be changing to get my query to return the correct values please? :slight_smile:


It is? Did you sum all the values returned by your query? I highly doubt that grafana total is wrongly calculated.
Maybe your values in InfluxDB are already averaged (and cannot be used to get a total) without some math?

Of course, if you change the aggregation function from mean to sum all the legend values will change.if have mean function in query only avg,and current in legend will always correct (depends on time range).

If you need max in legened to be correct you need max aggregation function in your query