Stop count when Sum target met

awbcollier

New Member
Joined
Apr 20, 2010
Messages
2
Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I have been trying to figure out a way to do this, and so far have failed miserably. I can't seem to develop an array function that works, and my VBA is not up to scratch enough to create this, although I think a loop function might do what I need.<o:p></o:p>
<o:p></o:p>
I have a row of data that holds dispatch values by week. I have a second row of data that holds stock levels by week. I simply want to create a third row that tells me how many weeks of demand a stock level will cover.<o:p></o:p>
<o:p></o:p>
The data looks like this (comma deliminated):<o:p></o:p>
<o:p></o:p>
Week, 1, 2, 3, 4, 5, 6, 7, 8, 9<o:p></o:p>
Stock, 26490, 24490, 22490, 20490, 18490, 14239, 17898, 13646, 9393<o:p></o:p>
Dispatch, 2000, 2000, 2000, 2000, 4251, 4251, 4252, 4253, 2350<o:p></o:p>
<o:p></o:p>
In this example week 1 would have 9 weeks of stock cover, week 2 - 8 weeks and week 3 - 7 weeks of cover.<o:p></o:p>
<o:p></o:p>
This is calculated by summing along the dispatch row until the cumulative sum of dispatch exceeds the current week’s stock level; then counting the number of weeks in the sum that cumulatively are less than (but closest to without being over) the total stock of that week.<o:p></o:p>
<o:p></o:p>
Currently we manually create a massive array that sums along up to 26 weeks in advance and then have a manual formula that finds the maximum value below the target. This then outputs the column reference and then calculates the number of weeks based on the difference between the week’s column and the column highlighted.<o:p></o:p>
<o:p></o:p>
This is massively inefficient and takes far too much time and makes files too large to email. I am sure this can be done with a formula, array or Dsum (maybe vba) but cannot figure it out. Any help greatly appreciated.<o:p></o:p>
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Let A1:J3 house the sample you provided...

B4, control+shift+enter (not just enter) and copy across:

=MATCH(B2,SUBTOTAL(9,OFFSET($B$3,0,0,1,COLUMN($B$3:$J$3)-COLUMN($B$3)+1)),1)

Is this what you intend?
 
Upvote 0
Let A1:J3 house the sample you provided...

B4, control+shift+enter (not just enter) and copy across:

=MATCH(B2,SUBTOTAL(9,OFFSET($B$3,0,0,1,COLUMN($B$3:$J$3)-COLUMN($B$3)+1)),1)

Is this what you intend?

Mr. Aladin,

Just for a knowledge, Is there something wrong to use the below non Array Formula?

=MATCH(B2,INDEX(SUBTOTAL(9,OFFSET($B$3,0,0,1,COLUMN($B$3:$J$3)-COLUMN($B$3)+1)),0),1)

Thanks in advance for your valuable advice.

Raj
 
Upvote 0
Mr. Aladin,

Just for a knowledge, Is there something wrong to use the below non Array Formula?

=MATCH(B2,INDEX(SUBTOTAL(9,OFFSET($B$3,0,0,1,COLUMN($B$3:$J$3)-COLUMN($B$3)+1)),0),1)

Thanks in advance for your valuable advice.

Raj

I'm quite familiar with that use of the INDEX function, even introduced it around here. It allows you avoid confirming the formula with the three key combination, but the formula is still an array formula in the sense it needs to crunch an array. Moreover, it requires an additional function call.
 
Upvote 0
Hi Aladin,

thanks for your insights here...I am trying to use this formula also, using it but must admit that I don't understand the syntax well. Would you please "word it out" once for me?

Thanks a lot!!
Nane


Let A1:J3 house the sample you provided...

B4, control+shift+enter (not just enter) and copy across:

=MATCH(B2,SUBTOTAL(9,OFFSET($B$3,0,0,1,COLUMN($B$3:$J$3)-COLUMN($B$3)+1)),1)

Is this what you intend?
 
Upvote 0
Hi Aladin,

thanks for your insights here...I am trying to use this formula also, using it but must admit that I don't understand the syntax well. Would you please "word it out" once for me?

Thanks a lot!!
Nane
1) The OFFSET bit builds up the following range objects:

B3, B3:C3, B3:D3, B3:E3, B3:F3, B3:G3, B3:H3, B3:I3, and B3:J3. The COLUMN argument supplies the size for each range, using B3 as the start cell.

2) SUBTOTAL runs SUM (which is function 9) on the ranges so created, creating a set of nine totals, each larger than the one that precedes.

3) MATCH attempts to match the figure in B2 against the set of increasing totals with match-type set to 1, so yielding a result showing when B2 obtains.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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