Announcements
cancel
Showing results for
Did you mean:
Creator

## Running total with a condition

Hi,

I am trying to calculate running total based on a condition. In the attached sample file, I have taken a sample data for one Customer and one Company. What I want to check is if the Balance for one period is equal (or close) to the sales. If not then add the sales of previous period and continue till the cumulative sales is close to (but doesn't exceed) the Balance.

Here is one example for April (201804):

1. Is April Balance equal to April Sales?

2. If it is less, then compare April+March Sales with April Balance

3. If still less, then compare April+March+Feb Sales with April Balance

4. Continue till the running Sales total exceeds the Balance, and then take the running total of previous step (as that is the closest but not greater than the April Balance)

Regards,

1 Solution

Accepted Solutions
MVP

Fixed the expressions now

10 Replies
Creator
Author

Any guidance... experts!!!

MVP

Look at the attached image and qvw

Creator
Author

Thank you Sunny for your help. The result is good for the month of April; however if you select other months, it doesn't give correct result. The calculation always seem to start from the period 201804 irrespective of which period is actually being selected.

This is what I get:

This is what it should be:

The calculation for Sales and Number of days should start from the selected period. eg if 201802 is selected, then the Balance for the period should be compared with Sales of 201802, and then keep on adding the sales of 201801,201712,... and so on.

MVP

Fixed the expressions now

Creator
Author

Thank you Sunny. This works great

Just wanted to know... can this be done at the back-end as well - may be five columns calculated at the script level !

Regards,

MVP

I think you might be able to do this in the script also

Creator
Author

Regards,