How about using Grafana’s fill(previous) feature? This does exactly that, no need for some workarounds.