Hi Keerthi,
I used a similar data to show whether the day has reached sales for day or else added to next day to show the demo.
The below code is for finding the amount to be paid after adding previous balance - To be paid
IF ISNULL(ZN(SUM([AMT PAID])) - LOOKUP(ZN(SUM([AMT PAID]) - [AMT TO BE PAID]), -1)) THEN [AMT TO BE PAID] ELSE ZN(SUM([AMT PAID])) - LOOKUP(ZN(SUM([AMT PAID]) - [AMT TO BE PAID]), -1) END
Use below code to find the amount balance that is paid in the next step - balance
[To be paid] - SUM([Sales])
A simple demo image for your problem -
Hope this helps you!