# (issue fixed) wrong derivative result?

I am querying a Measurement with 2 different queries. The problem is that the query that calculates the derivative is not returning correct values.

If I query the totals, I’m getting:

SELECT last(“Count”) FROM “OrderStatus” WHERE time > now() - 30m AND StatusId = ‘123’ GROUP BY time(120s), “StatusId” fill(0)
~
OrderStatus
StatusId:123
time last
2017-05-04T14:30:00Z 0
2017-05-04T14:32:00Z 0
2017-05-04T14:34:00Z 0
2017-05-04T14:36:00Z 2
2017-05-04T14:38:00Z 1
2017-05-04T14:40:00Z 0

But when I query the exact same but with the derivative, it is calculating it wrong:

SELECT derivative(last(“Count”), 1s) FROM “OrderStatus” WHERE time > now() - 30m AND StatusId = ‘123’ GROUP BY time(120s), “StatusId” fill(previous)
~
OrderStatus
StatusId:123
time derivative
2017-05-04T14:32:00Z 0
2017-05-04T14:34:00Z 0
2017-05-04T14:36:00Z 0.008333333333333333
2017-05-04T14:38:00Z -0.008333333333333333
2017-05-04T14:40:00Z 0

From minute 14:34:00 to 14:36:00 (2 minutes elapsed) it increased by 2.
An increase of 2 every 120 seconds = 0.0166(6) /s, which is the number I’m expecting to be returned.
However I’m returned the result of 0.008(3).

Then from minute 14:36:00 to 14:38:00 it decreased by 1, yet it reported the exact same amount of decrease.

And further, from minute 14:38:00 to 14:40:00 it decreased by a further 1, yet it reported 0 derivative.

Found the problem, “user error”.