Calculation Error with Group by and Nested Group by Transformation on a Counter PromQL

  • I have a counter metric of Prometheus and want to show a nested structure something like below i.e. Person1’s and his marks against it and a nested structure which shows marks per subject(refer snap1)

    Person1 | 75 |
    Subject1 | 30 |
    Subject2 | 45 |
    Person2 | 85 |
    Subject1 | 40 |
    Subject2 | 45 |

Achieved it using below method

QueryA:round(sum by (Person, Subject) (increase(CounterReported[$__range])))
QueryB:round(sum by (Person) (increase(CounterReported[$__range])))
Format for both is Table

Transformation applied are:

  1. Inner Join using field Person
  2. Organize fields by name
    Disabled Time1 and Time2
  3. Group by
    1.Person:Groupby
    2.Subject:Groupby
    3.ValueA:Calculate Last
    4.ValueB:Calculate Last
  4. Nested Group by
    Person:Groupby
    Subject:Ignored
    ValueA: Ignored
    ValueB:Groupby

Now coming to my issue when I open the dashboard it shows me above marks as expected and an immediate refresh on dashboard turns value to 0 for all the marks.

Same thing happens when I change time range i.e. if time is change to 5 hours it shows correct values and an immediate refresh button updates the values to 0.

Grafana version is 11.x

An immediate refresh return all values to 0