"Show percent change" on version 10.3

  • What Grafana version and what operating system are you using?
    10.3.1 running on kubernetes

  • What are you trying to achieve?
    I need to explain to my boss how this value is calculated.

  • How are you trying to achieve it?
    I need to explain to my boss how this value is calculated.

  • What happened?
    We have enabled “Show percent change” but we don’t understand how this math works.

  • Screenshots:

I tried to read the code, but I’m not good at programming: Stat: Add Percent Change Option by drew08t · Pull Request #78250 · grafana/grafana · GitHub

Can someone help me to conclude on how this 28.3% is calculated?
I can think of the following options:

a. 28.3% more users on the last 1 hour (based on Step)
b. 28.3% more users based on the same date 7 days ago (based on query option relative time)
c. 28.3% more users based on the last data point (we have one datapoint every 10 minutes)

“c” does not makes a lot of sense, as my app does not behave as such.

1 Like

I had a quick look at the code, and I think the relevant code bit is right here:

The way the calculation works is as follows:

  • The field gets reduced through the use of a special field reducer in the transformations package, called “diffperc
  • The way that calculation works is that it reuses the “diff” calculation, and then divides by the first non-null field value.
  • The way “diff” works is that it subtracts the first non-null from the last non-null value. (See reference here)

So over a 7-day period as in your screenshot, I think what’s going on here is that the first value is subtracted by the last value, then divided by the “starting value” (first non-null field value) and you get the result like that. Example, let’s say your data is:

null, null, 1, 2, 3, 4, 5, null, 5, 4, null

Diff would be 4 - 1, and diffperc would be (4-1) / 1 = 300%

3 Likes

Isn’t the % wrong with negative values ?
First value : -0.0491
Last value : 0.129

  • -362 %
    But we obviously increase

If you start with (positive) 2 and end up with 8, that’s a 400% increase.

If you start with -2 and end up with 8, the factor is -400%.

You have to multiply a negative number by a negative number to get a positive
result.

Antony.

yes so it’s not really working for mixed pos / meg values