From a17304f735894caa6ce14543279a293bc0c1d34e Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Sat, 25 Apr 2026 23:36:16 +0000 Subject: [PATCH] monitoring(uk-payslip): fix empty YTD gross YoY chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs: 1. Synthetic dates projected onto 1970/71 fell outside the dashboard's default time range (now-10y → now), so Grafana filtered out every point. Switched to a sliding 12-month window (CURRENT_DATE - INTERVAL '12 months') as the projection base, plus a per-panel timeFrom: "13M" override so the panel always shows the last 13 months regardless of the dashboard's time picker. 2. ORDER BY tax_year, pay_date violated Grafana's long→wide conversion requirement (data must be ascending by time). Wrapped in a CTE and re-ordered by the synthetic time column. Pivoted result is now a single wide frame with 7 series (2019/20…2025/26). --- .../monitoring/modules/monitoring/dashboards/uk-payslip.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stacks/monitoring/modules/monitoring/dashboards/uk-payslip.json b/stacks/monitoring/modules/monitoring/dashboards/uk-payslip.json index 5bd89a58..2978637c 100644 --- a/stacks/monitoring/modules/monitoring/dashboards/uk-payslip.json +++ b/stacks/monitoring/modules/monitoring/dashboards/uk-payslip.json @@ -2539,8 +2539,9 @@ { "id": 17, "title": "YTD gross salary — year-over-year comparison", - "description": "Cumulative gross pay built up month by month within each UK tax year (April → March). One line per tax year. Pay dates are projected onto a 1970/71 fiscal calendar so years overlay cleanly — the X-axis shows month-of-tax-year (April first, March last). Always shows all years; ignores the time picker.", + "description": "Cumulative gross pay built up month by month within each UK tax year (April → March). One line per tax year. Pay dates are projected onto a sliding 12-month window ending now, so years overlay cleanly without falling outside the dashboard's time range. X-axis shows month-of-tax-year (April first, March last).", "type": "timeseries", + "timeFrom": "13M", "datasource": { "type": "grafana-postgresql-datasource", "uid": "payslips-pg" @@ -2583,7 +2584,7 @@ "rawQuery": true, "editorMode": "code", "format": "time_series", - "rawSql": "SELECT (DATE '1970-04-06' + (pay_date - MAKE_DATE(SUBSTRING(tax_year, 1, 4)::int, 4, 6)))::timestamp AS \"time\", tax_year AS metric, SUM(gross_pay) OVER (PARTITION BY tax_year ORDER BY pay_date) AS ytd_gross FROM payslip_ingest.payslip ORDER BY tax_year, pay_date" + "rawSql": "WITH projected AS (SELECT ((CURRENT_DATE - INTERVAL '12 months')::date + (pay_date - MAKE_DATE(SUBSTRING(tax_year, 1, 4)::int, 4, 6)))::timestamp AS t, tax_year, SUM(gross_pay) OVER (PARTITION BY tax_year ORDER BY pay_date) AS ytd FROM payslip_ingest.payslip) SELECT t AS \"time\", tax_year AS metric, ytd AS ytd_gross FROM projected ORDER BY t, tax_year" } ] }