Show percentage change from this period to the previous period

I have a mysql database with a list of records and hoping to get a stat that shows the percentage change of the count of the submissions in the current time period compared to the same period before it.

e.g., If we are viewing this week we would see percentage change from this week compared to last week (positive or negative) or month or year.

I thought that time shift might be a useful start but it seems to apply to all queries for that panel and isn’t dynamic based on the time period chosen.

If adjusting for time period isn’t possible then this month (so far) compared to last month, or fixed 30 day blocks would be acceptable.

I’ve tried a single simple query and then in query options putting min interval 30d and in the Stat Display options chosen difference percent. It shows a number but its not correct for what I need. for example on the 2nd of May it’ll show two days of may compared to 30 days of april, not the same ‘sized’ periods for comparison.

Thanks in advance!

Hi @dignz,

It’s not exactly what you want, but you could use a stat panel with a difference percent calculation:

This would then calculate the percentage of change using your time-range as a start and finish. This isn’t the same as what you wanted, but a potential workaround that’s still dynamic

Thanks, its very close but not quite what I need.

If I could some how make a query that collected -60d to -30d as the start value and -30d to now as the final value then this difference percent would show what I needed it to as long as ‘now’ can be changed to whatever date we select. Maybe making a custom SQL query could manage that but I’m not entirely sure on how to hook into the right values to make it work.

1 Like

I agree that performing all your transformations inside MySQL will be much more performant than using transformation inside Grafana.

Unfortunately I’m not super helpful with forming SQL queries…