Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for
Search instead 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)

Thanks in advance for your help.

Regards,

Bhaskar

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.

Thanks again for your help.

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 !

Thanks again for your help!

Regards,

Bhaskar

MVP

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

Creator
Author

Can you please help, if that doesn't require too much of an effort.

Regards,

Bhaskar

MVP

It will require some time and effort to come up with the script which does what you want.. I will try to work on it as and when I get some time

MVP

Having looked at this a little more... it will be very challenging to do this in the script because this is mostly driven by selection. Is there a reason you are looking to do this in the script?

Community Browser