There are a couple of things that confuse me in your post: 1. Does the ID_Payment not play as a factor in the sorting order? - There are two payments between '14JUN2019' and '17JUN2019', then nine payments between '18JUN2019' and '01DEC2019'. - Since we are calculating a running calculation for how much debt was payed off at what point and what debt was remaining, wouldn't we need to sort across ID_Payment? (assuming that wasn't just a random number, which by looking at it, does not appear to be random). 2. If I am reading this correctly it appears as though the field, 'Payment_Sum' is the amount paid in that specific transaction. - If that is the purpose of that field, why would we want the first observation in your results to show 'payed' as 0 if the 'payment_sum' was 59,079.99? - I would think that the first observation would populated 'payed' with 59,079.99 and then the following 'to_pay'(remaining debt) would be 920.01 Understanding these items a little better might help me understand what needs to occur to accomplish the results you need.
... View more