How to query monthly energy InfluxDB 2.0?

InfluxDB v2.7.1
Grafana 10.0.1

I want to create bar graph monthly energy.

from(bucket: “IDA”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “Electric” and r._field == “P” )
|> aggregateWindow(every: 1mo, fn: sum, createEmpty: true)
|> drop(columns: [“host”, “topic”])
|> cumulativeSum()

My data is Active Power, P (kW).
P is send every 1 minute.
I want to convert P to Energy (kWh) and show on the graph.

Example graph that I want to get it

Another question, how can I offset -7h?

I try to use this “option location = timezone.fixed(offset: -7h)”
from this https://docs.influxdata.com/flux/v0.x/stdlib/timezone/fixed/
but I cannot offset it.

My graph on Grafana.

Here is what I do (not completely the same as what your query, but should help you get started):

from(bucket: "EIAtest7")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "ElectricPowerOperations")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["type"] =~ /^${type:regex}$/ )
  |> filter(fn: (r) => r["region"] =~ /^${region:regex}$/ )
  |> group(columns: ["region", "_measurement"], mode:"by") 
  |> aggregateWindow(every: 1mo, offset: 1d, fn: sum, timeSrc:"_start")  // sums the total used per month
  |> yield(name: "monthly_data")
1 Like

@roongrojp

Also see here.

Thanks for your help.

I updated my energy chart.

I change data from Power [kW] every 1 minute to Energy (accumulated) [kWh]

I can create daily energy chart but I still cannot create monthly energy chart (It does not show value on first month).

For someone who wants to create the graph like me.

option location = {zone: “UTC”, offset: 7h}

from(bucket: “IDA”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “Electric” and
r._field == “actEnrg” )
|> aggregateWindow(every: 1d, fn: last, createEmpty: true, timeSrc: “_start”)
|> difference(nonNegative: true, initialZero: false, keepFirst: true, columns: [“_value”])
|> drop(columns: [“host”, “topic”])