Hi,
i think that is the most difficult Query i have in Flux needs to be converted to Postgresql:
import "timezone"
// Set location to be Europe/Berlin
option location = timezone.location(name: "Europe/Berlin")
from(bucket: "solarpower")
|> range(start: -12mo, stop: now())
|> filter(fn: (r) => r["_measurement"] == "solar")
|> filter(fn: (r) => r["_field"] == "todaykwh")
|> aggregateWindow(every: 24h, fn: last, offset: -1s, createEmpty: false)
|> truncateTimeColumn(unit: 1m)
|> aggregateWindow(every: 1mo, fn: sum, createEmpty: false, timeSrc:"_start")
I have tried this with 2 Select Querys:
SELECT
SUM(todaykwh) AS "monthly_sum"
FROM (
SELECT
max(todaykwh) AS "last_todaykwh"
FROM
solarpower
GROUP BY
date_trunc('day', time)
)
GROUP BY
date_trunc('month', time)
That didnt work i get an Error todaykwh didnt exists
timestamp / todaykwh
timestamp/ 5000
timestamp/ 4999
timstamp/4998
This latest or max value (5000) from 24hours and all latest 24hour values summarized for 1 month. over 12 months or 12 bars in Grafana.
