# Using non\_negative\_derivative() with implied first value of 0

**URL:** <https://community.influxdata.com/t/using-non-negative-derivative-with-implied-first-value-of-0/5523>\
**Category:** Dashboards\
**Created:** [June 13, 2018, 10:57pm UTC](https://community.influxdata.com/t/using-non-negative-derivative-with-implied-first-value-of-0/5523 "2018-06-13T22:57:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ofaaland](https://avatars.discourse-cdn.com/v4/letter/o/edb3f5/32.png) [@ofaaland](https://community.influxdata.com/u/ofaaland)\
**Post date:** [June 13, 2018, 10:57pm UTC](https://community.influxdata.com/t/using-non-negative-derivative-with-implied-first-value-of-0/5523/1 "2018-06-13T22:57:22Z")

</div>

Hi,

I am a new user of influxdb. I believe I did all the appropriate research before posting here, but if I missed something please point me at it. I am using influxdb 1.5.2.

I am ingesting counters which increase monotonically except when they are zeroed. So, the points might look like this, where below all have the same tags:

time counter  
3 2  
4 7  
5 12  
25 1  
26 8  
27 20

Where the counter did not exist at times 1-2, 6-24, or \>=27.

I would like to calculate the non-negative difference between subsequent points, but with the caveat that a missing measurement should be counted as 0. So I want to get output like this:

time difference  
3 2  
4 5  
5 5  
25 1  
26 7  
27 12

but “select non\_negative\_difference(counter,1s) as difference” or similar behaves as advertised and gives me 4 differences instead of 6, omitting the ones at time 3 and time 25.

Does anyone have any suggestions?

thanks!
