Calculate based on actual full calendar month not 4w

  • What Grafana version and what operating system are you using?

Latest release

  • What are you trying to achieve?

Calculate a monthly usage of KWH based on a cumulative running total.

  • How are you trying to achieve it?

The database entries are cumulative usage of KWH over time. currently I use this to calculate daily use, and it works great, also works great for weekly stats.

SELECT spread(“energy”) FROM “eegridmea” WHERE $timeFilter GROUP BY time(1d) fill(null)

So I can get also data for the last 4 weeks, which is sort of an approximation of monthly usage, but of course realize that a month is certainly not 4 weeks exactly each month, so over time is is going to “slip” away from being an actual month.

SELECT spread(“energy”) FROM “eegridmea” WHERE $timeFilter GROUP BY time(4w) fill(null)

So I guess the question is how to calculate monthly usage, so that it is the actual month, based on dates. I could probably write some javascript and drop that in Influx, but seems like there should be a way to query perhaps the first and last days of the month, and get the difference.

I’ve looked over quite a few other posts and not found anything specific to this, so any points in the right direction would be greatly appreciated+

Thanks everyone+

@butteryak I would recommend you make the jump from InfluxQL to Flux. Aggregating your data by calendar month or year has been fully supported in Flux since 2019.

1 Like

yeah, I was just reading about that, I may need to do so+ thanks for the nudge :wink: