Show % delta change between current time period and previous

Hi there

I have a SQL Server data source, with a query like this:

SELECT 
  Timestamp AS "time", 
  Name,
  AverageInMins
FROM
  Metrics.dbo.BusinessMetrics a
WHERE
  $__timeFilter(Timestamp)
ORDER BY
  Timestamp ASC 

That returns data that i can plot on a basic time series graph. Great.

Now, i want to show the % change between the current time period and the previous.

To take an example, let’s say i am viewing the last 90 days of data. The previous 90 days average value of AverageInMins is 100. Now, it’s 80 for the last 90 days. I want to show a value of -20%, somewhere.

My questions are:

  • How can i write this SQL query? I know how to get the last 90 days, but how do i get the previous 90 days too? (as i assume i need to use a grafana variable to get the current ‘time filter’, and minus that from the current time?)
  • What is the best “visualization” for this setup? Can i put it on a time series chart alongside the graph, or do i need a seperate one?

Many thanks :slight_smile: