# Kapacitor difference

**URL:** <https://community.influxdata.com/t/kapacitor-difference/4335>\
**Category:** Systems\
**Tags:** kapacitor\
**Created:** [March 13, 2018, 1:09am UTC](https://community.influxdata.com/t/kapacitor-difference/4335 "2018-03-13T01:09:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctaity](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ctaity/32/1096_2.png) [@ctaity](https://community.influxdata.com/u/ctaity)\
**Post date:** [March 13, 2018, 1:09am UTC](https://community.influxdata.com/t/kapacitor-difference/4335/1 "2018-03-13T01:09:46Z")

</div>

I have a mesurement like this

TIME iD SOLD\_QUANTITY  
XXX 1 1  
XXX 1 2  
XXX 1 2  
XXX 2 1  
XXX 2 1

I wish with kapacitor get the difference betweent last value and new value with stream. I trying to do:

dbrp “ml”.“autogen”

stream  
|from().measurement(‘items’).groupBy(‘item\_id’)  
|window().period(1d)  
|difference(‘sold\_quantity’)  
|log()

But dont work, some body can help me. Thanks

---

<div class="post-metadata">

**Author:** ![katy](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/katy/32/855_2.png) [@katy](https://community.influxdata.com/u/katy)\
**Post date:** [March 26, 2018, 8:40pm UTC](https://community.influxdata.com/t/kapacitor-difference/4335/2 "2018-03-26T20:40:11Z")

</div>

Can you post your expected result versus actual result? That would be helpful!

---

<div class="post-metadata">

**Author:** ![ctaity](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/ctaity/32/1096_2.png) [@ctaity](https://community.influxdata.com/u/ctaity)\
**Post date:** [March 26, 2018, 11:58pm UTC](https://community.influxdata.com/t/kapacitor-difference/4335/3 "2018-03-26T23:58:40Z")

</div>

> [@katy](#):
>
> result versus actual re

I have something like this: table products  
time . item\_id . sold  
xxxxxxx 1 4  
xxxxxxx 1 6  
xxxxxxx 1 7  
xxxxxxx 1 7  
xxxxxxx 1 8

and i put a new record  
xxxxxxx 1 9

My spected result is the diffrence betweent the lastrecord and new record:  
xxxxxxx 1 1

and output this into influxdb table.
