How to make difference between rows from different columns InfluxDB

influxdb
#1

I’m struggling with an InfluxDB query.

So I have this kind of table :

**timestamps counter val1 val2
**1553853840000 8109 4 5
**1553850240000 8066 17 8
**1553814240000 7581 12 2

What I want to achieve is :

-take the current row and make a difference with the sum(val1+val2+counter) of the previous row.

So that I have this table :

**timestamps counter val1 val2 difference
**1553853840000 8109 4 5 18
**1553850240000 8066 17 8 471
**1553814240000 7581 12 2 …

I tried with difference() function but it only make the difference between the rows. I tried with compute the sum in an other column but it’s the same issue because I didn’t find how to make difference between different rows from different columns