Query Timeout InfluxDB on 3Month Power Calculation

Hi,

i have Grafana 9.4.7 installed on my Raspberry Pi 4B with 64bit Raspian OS

My Problem: I have a query for Power Consumption per Month for the last 3 Months. Grafana is calculating very long for this Query with the result that i get a Query Timeout.

How can i optimize that Query ?

import "timezone"
// Set location to be Europe/Berlin
option location = timezone.location(name: "Europe/Berlin")

from(bucket: "solarkraftwerk")
  |> range(start: -2mo, stop: now())
  |> filter(fn: (r) => r["_measurement"] == "solarkraftwerk")
  |> filter(fn: (r) => r["_field"] == "totalPmeter")
  |> difference()
  |> truncateTimeColumn(unit: 1s)
  |> aggregateWindow(every: 1mo, fn: sum, createEmpty: false, timeSrc:"_start")

In this case i have reduced the Query to 2 Months (this works) but calculates very long.