I have the following query to get an average of units on the preceding 12 months in an interval but my problem is that the 12 preceding months is not taking into account ISO week 1 in the year, say this example:
SELECT
*,
avg(units) OVER (
ORDER BY to_date(year::text || '-' || week::text, 'IYYY-IW')
RANGE between interval '12 months' preceding and current row)
FROM
rolling_year_table
order by year,week;
Basically ISO week 1 2020 (which is actually '2019-12-30' is not taken into account in the calculations.
Is there a way to say 12 months preceding and current row but using ISO weeks?
Thanks,