I have a dataset on multiple customer's revenue information like the
following:
Id customer revenue
Z11 xx1 y1
Z21 xx1 y2
Z31 xx1 y3
Z12 xx2 k1
Z22 xx2 k2
Z32 xx2 k3 and so on.
I need to create a new data based on the following criteria. If the sum of
revenue by customer is <=999, I need to write
Customer revenue
xx1 sum of y
xx2 sum of k
But if the sum of revenue by customer is >999 and <=1998, I need to write
Id Customer revenue
001 xx1 999
002 xx1 sum of y-999
001 xx2 999
002 xx2 sum of k-999
and if the sum of revenue by customer is >1998 and <=2997, I need to write
Id Customer revenue
001 xx1 999
002 xx1 999
003 xx1 sum of y-1998
001 xx2 999
002 xx2 999
003 xx2 sum of k-1998
Can anyone please provide me any help on this?