After contacting grafana directly I received the answer that this is not currently possible. All such computation must be done by the data source, not by grafana.
Answer from Chor Hatara Hud'u Keturi on Stack OverflowAfter contacting grafana directly I received the answer that this is not currently possible. All such computation must be done by the data source, not by grafana.
Not exactly an answer to the original question but since the answer is "It's impossible" I thought I'd share my work-around for this missing feature. As this is what I did instead.
Here is how to do it in MariaDB:
SET @cumul := 0;
SELECT
`seq`
, @cumul := @cumul + `seq` AS `cumul`
FROM seq_1_to_20;
The data has to be ordered in sequence for it to add up correctly.
to explain it:
- set a variable called @cumul
- add the value you want to make cumulative and select it as a column
EDIT:
In Grafana it does not let you run 2 queries at the same time and it also makes use of Connection Pooling, meaning it speeds up the system by running queries over different connections, so if you run them as 2 queries the variable is not reset.
After hacking at it, this version works in Grafana for MariaDB (and probably MySQL too)
SELECT
`seq`
, @cumul := @cumul + `seq` AS `cumul`
FROM seq_1_to_20, (SELECT @cumul:= 0) b
I've found the answer, we need to utilize the "Script" option.
First we set a metric to get sum of apple, then the result of sum of apple is added to doc["orange"].value