Summation of segments

Hi,

I’m trying to achieve a summation on ‘segments’, but failing to do so. I hope somebody can help me out in the right direction.

What i’m trying to achieve is : ( for example )

Calculate the sumation of the max value :

segment 1 : 3000
segment 2 : 3133
segment 3 : 3128
segment 4 : 3199
segment 5: 3252

The total of this is 15712, and is what i’m trying to achieve.

Currently my flux script looks like :slight_smile:

data = from(bucket: "....x")
    |> range(start: v.timeRangeStart, stop:v.timeRangeStop)
    |> filter(fn: (r) => r._measurement == "${DeviceID}" and (r._field == ".....x"))
    |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
    |> filter(fn: (r) => r......x> 0 )
    //|> yield(name: "squared")
data1 = data 
    |> derivative(columns:[".....x"],unit: 10s, nonNegative: false)
    |> filter(fn: (r) => r......x> 100 )
    |> set(key: "Type",value: "TotalWeight")
    //|> yield(name: "test") 
 
union(tables: [data, data1])
    |> pivot(rowKey:["_time"], columnKey: ["Type"], valueColumn: "....x") 
    |> filter(fn: (r) => r.TotalWeight > 0 )
    //|> cumulativeSum(columns: ["null"])

        

I’ve tried using the cumulativeSum function, integral funtion etc etc… but not getting the result im looking for.

I hope someone can help me out.

Thanks,
Regards

Hello @bart1992
This is sort of related to this:

It’s very hard to tag events with Flux in InfluxDB or reset a count.