What I'm doing wrong? Polystat transformations

  • What Grafana version and what operating system are you using?

9.5.2 @ Debian

  • What are you trying to achieve?

Display the metric difference change % using dynamic interval

  • How are you trying to achieve it?

Using transformations after querying the first and last metrics of the interval

  • What happened?

Is not showing the expected values, way less

  • What did you expect to happen?

Metric should be in the order of 1% to 3%

  • Can you copy/paste the configuration(s) that you are having problems with?

Added in a screenshot

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.


  • Did you follow any online instructions? If so, what is the URL?

Official grafana doc

Check this function out

1 Like

Thanks for that @yosiasz, I have created the polystat using the described function, however the numbers still wrong. I suspect of problems with the interval, the following is 24h and should be around 3% of difference.

Did you fully read the spread function documentation?

spread() returns the difference between the minimum and maximum values in a specified column.

I think I did @yosiasz, is just one line anyway, and I think is working as expected. Iā€™m having issues with the interval, I want it to be dynamic using the dashboard time range, could you check the screenshot attached in my previous message please?

Remove everything else and leave the spread query. It does all of it

Thanks @yosiasz but is not working at all. Do you mind to explain why the spread difference will work as percentage? Not documented.

Solution was fairly easy, just grab first and last metric and do the math, no function needed at all.

1 Like

Works indeed but performance wise this is costly as you are hitting the back end twice.
And you are indeed using 2 functions first and last .

With spread you do it once and then apply the percentage math.

Thanks @yosiasz, but math wont work in line with the time range as explained before, main need is to be dynamic metric, also is not handling negative differences. Both issues remains unsolved.