Difference is not working properly

Hi, I am using Kapacitor with the following TickScript. I want to get the difference between the ‘bid’ value of the current point and the previous point from the tick measurement which need to be grouped by 3 tag fields.

var diff_bid = stream
|from()
.measurement(‘tick’)
|groupBy(‘server’, ‘app’, ‘pair’)
|difference(‘bid’)
.as(‘value’)
.usePointTimes()
|window()
.period(10s)
.every(10s)

I tried to feed one day data file into InfluxDB, at start, the difference() function is still working fine. But start from the 2nd hour of the data, the difference value becomes incorrect… is there anything wrong with my script? Many thanks.