Time shift based on dashboard timepicker range

  • What Grafana version and what operating system are you using?
    Grafana v10.1.1 (0cfa76b22d)

  • What are you trying to achieve?
    I have a simple postgres query which gets a count for the selected time range (using $__timeFilter(time)).
    I’d like to additionally display a comparison of that data for the previous range i.e. if the time picker is set to last 7 days, the comparison should be the previous 7 days. If the time picker is set to last 30 days, the comparison should be the previous 30 days.

  • How are you trying to achieve it?
    I have 2 panels with same query. The first panel uses query options to set the Relative time to 30d. The second panel uses query options to set the Relative time to 30d and additionally sets the Time shift to 30d.

  • What did you expect to happen?
    The above works just fine but I’d like to set the relative time and time shift based on the time picker values and not a fixed 30 days. It feels like it should be possible (maybe using grafana global variables?) but I can’t figure it out so any help would be much appreciated.

Thanks!

1 Like