Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
pvanderkolk
Partner - Contributor III
Partner - Contributor III

Deplete oldest numbers and their amount when new arrives

Hi all,

I was wondering if you could help me with below problem. When I receive a new number with an amount (first table), I want that this amount deducts my oldest open numbers (second table) and rounds it up. So if an open invoice will be taken partly, the amount of the new number needs to increase so that the partly taken number can be taken fully.

Table new
NumberDateAmount
36A02-05-2019225

 

Table open
NumberDateAmount
1A19-04-2019453
3B15-04-2019348
465A02-04-201918
36C05-03-201918
49A05-03-2019119
   

 

So in this case the numbers 49A, 36C, 465A and 3B (the four oldest numbers) are being taken and the amount that needs to be taken is 503 instead of the initial 225. 

I don't want to mess up my current tables, but want to add the above sentence as text object to the sheet. I've added a simple QVW, where you can also see the text object.

 

I hope I've made myself clear and that you can solve this problem. Thanks in advance!

 

Regards, Pim

 

 

1 Reply
pvanderkolk
Partner - Contributor III
Partner - Contributor III
Author

I hope it's a bit clear, maybe I can help a bit more. Below you see the formula that gives the right answer for this example. But as you don't know how many old numbers will be covered by the new amount, this needs to have a loop. And that is where my struggle is; how to create a loop that's checks per number (sorted from oldest to newest) if it exceeds the new amount.

If(

Sum(AmountNew)>

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen)),

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen)))+

If(

Sum(AmountNew)>

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen)),

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen),2))+

If(

Sum(AmountNew)>

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen))+FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen),2),

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen),3))+

If(

Sum(AmountNew)>

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen))+FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen),2)+FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen),3),

FirstSortedValue(AmountOpen,If(AmountOpen>0,DateOpen),4)))

 

Hope this helps.