need spill formula

Scott R

Active Member
Joined
Feb 20, 2002
Messages
493
Office Version
  1. 365
Platform
  1. Windows
Rows 2:8 show inputs. Rows 10:14 show desired output--I'd like a dynamic array formula in B10 that spills to B10:C14 (two columns in this example but I really need to spill to 40+ columns).

B2: Item1 needs 10,000 of purchases.
B8: Total purchases are 50,000.
B10: 10,000 of the purchases are allocated to Item1, so the new balance for Item1 is 0, and there are 40,000 of purchases to allocate to Items 2, 3, and part of 4.
Repeat for each Month (column).

So it's basically Rows 2:6 minus Row 8 = Rows 10:14, where no values in 10:14 would be negative and allocation order would cascade from Item1 to Item5.

Book2
ABC
1Month1Month2
2Item1 begin bal10,00010,000
3Item2 begin bal11,00023,000
4Item3 begin bal26,00021,000
5Item4 begin bal7,00011,000
6Item5 begin bal29,00015,000
7
8tot purchased50,00020,000
9
10Item1 end bal00
11Item2 end bal013,000
12Item3 end bal021,000
13Item4 end bal4,00011,000
14Item5 end bal29,00015,000
Sheet1
 
Here's what I landed on:
BYCOL spills right, VSTACK spills down (thx for the tip, Sofia!)

Excel Formula:
=LET( ary, B2:C6,     purch, B8:C8,
           DROP( REDUCE( "", SEQUENCE( ROWS( ary )), LAMBDA(a,b, VSTACK( a,
                           LET( prevCumul, IF( b = 1, SEQUENCE( , 2, 0, 0 ), BYCOL( TAKE( ary, b - 1 ), LAMBDA(c, SUM( c )))),
                                    bbal, CHOOSEROWS( ary, b ),
                                    ebal, IF( prevCumul > purch, bbal, bbal - purch + prevCumul ),
                                    IF( ebal < 0, 0, ebal ))))),
   1 ))

Out of curiosity I tested the formula and it seems that there is some issue with the first row when the first value is equal or greater than total it adds the column number to the sum.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top