Grafana how to calculate - 5 min (metric_value before 5 min)

I am using Grafana with ElasticSearch as the datasource, i wrote a simple Lucene Query for Grafana Stat panel and i am summing up that value for visualization. The sum metric works fine and i could see the metrics getting displayed. But my requirement is Not just to sum this metric but be able to compute the Difference of the sum which was some duration ago.

For example
previousSum = sum which was 5 minutes ago
currentSum = current Sum
where previousSum, currentSum are being computed for the same metric.
and then compute (previousSum - currentSum)/currentSum to get the % change for that specific metric. Any help is greatly appreciated.

You can use sum, then add new calculation using derivative, then hide the sum calculation.

Fadjar Tandabawana

thank you FadJar !!.

As an alternative can I use this for calculating - 5 min (metric_value before 5 min) ? (
This plugin is built as a datasource plugin that comapre and contrasts different time shifts data