Offsetting by 1 year minus 1 day

Hi,

I’m very much a beginner with PromQL. I have the following use case. I gather solar production data from Home Assistant via Prometheus to build charts in Grafana. One of the charts I have built shows the peak production per day as one curve, and the corresponding peak production the previous year on the same day as another curve.

The “current” curve is formulated as such:

max_over_time(homeassistant_sensor_energy_kwh{entity="sensor.esolar_pvelec"}[23h] offset -1d) != 0

Notes: it’s 23h because I found that with 1d, if the previous day had a higher maximum it will be repeated. It seems Grafana uses 00:00 as the reference time, so removing 1 hour during night time does definitely not prevent finding the daily maximum. I added != 0 to filter out outage days with no production.

Importantly there is an offset of -1d because the [23h] offset goes backwards from the reference time of 00:00 for each date, yet I want the maximum during the 23h that follow that timestamp.

The “1 year ago” curve is currently:

max_over_time(homeassistant_sensor_energy_kwh{entity="sensor.esolar_pvelec"}[23h] offset 364d)  != 0 

And this works right now. But after 29 February it will be offset by one day. I’d need to wait until then and change to 365d or 1y, and change again after 1 year. Really what I want is 1y-1d, but I couldn’t get this, or any similar combination I tried, to work.

Is there a way?

Thank you!
P.