Monthly bar chart using FLUX > Data needs to be shifted 1 month to the left

Using Grafana 9.4.7, running inside docker on synology NAS.

I’m plotting the energy production of my solar panels in a monthly bar chart (normal time series). I use a FLUX query as folloing:

from(bucket: "openhab_db")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["item"] == "Solis_etotal")
  |> aggregateWindow(every: 1mo, fn: last, createEmpty: false)
  |> difference(nonNegative: false, columns: ["_value"])

Solis_etotal is a measurement that is a cumulative value of the total energy production. Hence, to know the monthly produced values I use an aggregate per month based on the last figures and then calculating the difference.

For example for February it calculates the difference between the last value of February and the last value of January, which is exactly the produced amount for February.

The values are correct, however the only issue that I have is that the value of February is displayed in the month of March. See screenshot below: the value of 198kwh is indeed the correct value for February, however the value is stated on the day of March 1st, and hence it appears above the month of March.

In the below grapgh, every bar should therefore be shifted 1 month to the left.

What am I doing wrong here? How can I ensure that the value of February is effectively displayed above 02-2023 and not above 03-2023?

Welcome @Sceppi to the Grafana forum. Have a look at this thread. Changing your aggregateWindow function to something like this may help.

|> aggregateWindow(every: 1mo, fn: last, createEmpty: false, timeSrc: "_start")

1 Like

Hi @grant2 , thanks for the warm welcome! Have been using Grafana for some time, but this was my first post on the forum.

Thanks for the solution, works like a charm!