I have data that is being collected from a counting sensor. The counter itself is reset every time a new stock is applied to the machine giving a sawtooth appearance to the data. My question is how would you go about summing just the peaks from this data over a user specified range (so probably using the v. variables)? It always resets to 0 so I suppose somehow you could just add the rows where row number =0 minus 1. I’m just not clear on how you would go about this.

@woodson welcome to Influxdata community!

If the value is either zero or a number and you need the sum of numbers then you can use sum function for a time range.

The other logic suggested by you “find the row with value zero and get the peak value from row - 1” can be achieved using map function.

Kindly try and let me know if you need help writing the actual query.

Thanks!

How would sum work to find the sum of max values? I can’t know how many peaks there will be.

And yes precisely, how could you use the map function? There doesn’t seem to be any concept of row number on which to iterate.

@woodson You kind of need to define the interval that you want to calculate the max for? In your data, there isn’t a consistent timeframe for each “phase,” which makes it hard to define the intervals to return the maximum value in. Right now, there isn’t an easy way to detect these phases.

However, I think there’s a simpler solution here. From what I gather, you’re essentially trying to a negate the resets and just have a running total? If that’s the case, you can use `increase()`

.

```
// your current query
|> increase()
```

That’s right. And the interval unfortunately is not fixed! There may be some other user input I could use but it’s not clear to me how to tie one event to another.

I will look into the increase() function, thanks.