Kapacitor difference

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

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

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.