Calculate sums between events

Hey there,

i have a question about data handling in Grafana.

Target: Calculate driven range between battery loadings.

I have 2 different Influx Datasources. A has data about loading the battery. B has data about the driven ranges.

I can show booth sources as “mixed Datasource” into a graph. So I get a bar for loading, 5 bars for driven ranges, the a loading bar again and so on.

What I want is, to get a sum of the ranges between the loadings.

Example:
battery loading
driven 4km
driven 2km
driven 8km
loading
driven 15km
driven 4km
loading

should shown as
loading
driven (sum) 14km
loading
driven (sum) 19km
loading

So is it possible to do that in Grafana ?

Thank for help
regards
Manuel

I believe that using Flux, you could accomplish this by summing all values where the tag “driven” = TRUE. When “loading” the tag “driven” would be “false”. Not sure if that is how you set up your data, but it should be possible to create a map function that looks for a positive driven value.