Search code examples
grafana

How to use selected time range on Grafana dashboard in the panel query?


How to use selected time range on Grafana dashboard in the panel query?

The panel I am choosing is a pie chart. I set the values as seconds. I query from my SQL database table extra data in seconds to subtract from the time range in seconds: Grafana dashboard time range in seconds - my query result should be the result.

I tried to use the answers from this thread, though it didn't help out.


Solution

  • You can get length of time range in seconds used by dashboard with the following query:

    select ($__to - $__from)/1000 as "range"
    

    Then you can use this expression as part of any query as usual.