Retail - Excel Forward Cover Calculation

graemestown

New Member
Joined
May 10, 2019
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hi All
I need to solve a 'forward cover' calculation. I work in retail.
Here is the problem
I end week 1 (start week 2) with 500 units of stock
If I sell 110 units in week 2 I end with 390 units of stock and so on. I have intake in week 4 which tops up my stock.
My question is. How many weeks of future sales will each closing stock value service. Starting in week 1 I know I have enough stock to service sales at least up to week 6 and then part of week 7. So the answer at this point would be 6, in week 2 the answer would be 5 and so on...
How do I do this with a formula which can be pulled across and constant evaluating how many weeks into the future my stock will last, the data will be perpetual?


Weeks12345678910
Sales110120130140150160170180190
Opening Stock500
Intake300
Closing Stock500390270440300150-10-180-360-550
Forward Cover??
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi, would something like this give you what you need ?

Its not perfect, and the only caveat I have here is that you need to define your data range in the formula to start. (eg. formula in B7, I define as B7:K7 for this table). Then as you copy across, it moves the columns on. You CANNOT have any more data in the Row 7 alongside the right of your table, else it will probably fail incorrectly.

So for example it could work if you have 52 weeks defined in your sheet for a given year, and then up to 52 columns blank on the right of the table.

Book1
ABCDEFGHIJK
1
2Weeks12345678910
3Sales110120130140150160170180190
4Opening Stock500
5Intake300200
6Closing Stock50039027044050035019020-160-350
7Forward Cover7654321000
Sheet1
Cell Formulas
RangeFormula
C6:K6C6=+B6+C5-C3
B7:K7B7=IF(MAX(SCAN(0,B6:K6,LAMBDA(a,v,a+IF(v>0,1,0))))-1>0,MAX(SCAN(0,B6:K6,LAMBDA(a,v,a+IF(v>0,1,0))))-1,0)


Rgds
Rob
 
Upvote 0
Solution
I have no idea how you did that but it works, that's pretty impressive. I get the gist of what you're doing, so can adjust the formula as required. Thanks so much!
 
Upvote 0
Youre Welcome .. thanks for the feedback, glad its ok for you

Rob
 
Upvote 0
I'll try to explain what its doing for you step by step:

SCAN is a formula which is going to look at each value you specified in a range, and take that value into the LAMBDA formula to be worked on.
SCAN(0, .... [the 0 here is resetting a starter value for 'a' (or accumulator) to zero. We will use this accumulator later to count the number of weeks. We could put '-1' as a starting value - but more on that later.
SCAN(0, B6:K6 ... [B6:K6 is the range that we will look at, cell by cell, left to right. ]

So the first time we enter this SCAN loop, it picks up '500' as your closing stock from B6. It takes that into the LAMBDA formula as a value stored in 'v'.

SCAN(0,B6:K6,LAMBDA(a,v, ... so here, as we go into the LAMBDA formula, we are taking variables 'a' (=0) and 'v' (=500). Then we are going to perform some maths on those values.

SCAN(0,B6:K6,LAMBDA(a,v, a + IF(v>0,1,0))) - so the math we apply is to check if 'v' > 0 eg. do we have a positive Closing Stock left over this week. If yes, then we will add 1 to 'a' If no, we add '0' (or 'a' stays as it was.)
So the result of that formula first time around would be to put a '1' in cell B7. (seen in B10 in the below example picture)

Next, as its a SCAN formula, its going to look at the next cell in your defined range. So this time around, it's Cell C6, and that contains 390.
So its now asking if 390 is greater than 0, and if it is, then add another 1 to 'a'. This new value of 'a' (now = 2) will be put into cell C7.

So it repeats this process until it does all the range (B6 to K6), to give what would normally appear as this : (I have these in row 9 & 10 on my sheet for example purposes only)

Book1
ABCDEFGHIJK
9Closing Stock50039027044050035019020-160-350
10Forward Cover1234567888
Sheet1
Cell Formulas
RangeFormula
B10:K10B10=SCAN(0,B6:K6,LAMBDA(a,v,a+IF(v>0,1,0)))
Dynamic array formulas.


So, as you look along the row, you can see it has counted 8 weeks before it stops (as yourClosing Stock is now below zero.

Clearly, '1' in cell B10 above is not what you want to see - as it is not 1 week of stock. You want to see the 8 value from the other end, so we use MAX().


=MAX(SCAN(0,B6:K6,LAMBDA(a,v,a+IF(v>0,1,0)))) This just gives us the maximum number from the range of values we just created with the scan/lambda.
=MAX(1 2 3 4 5 6 7 8 8 8) = 8 So, we get a result of 8 put into what would be Cell B7. The rest of the values are ignored, and thats why in the original post, you don't see the intermediate values above - as they've been kind of hidden/removed by the MAX() statement.

So when we copy this formula across the cells, we now get just one result per cell (= weeks of Forward Cover).

BUT, as you can see above, the week before (in cell I9) is a partial only, as it has 20pcs, so we need to subtract 1 from the end result to give us just "7" in Cell B7.

=MAX(SCAN(0,B6:K6,LAMBDA(a,v,a+IF(v>0,1,0))))-1 so I add the '-1' at the end.
(Here, we could have used instead of '0' as our starting accumulator, a "-1", as I mentioned earlier, as end result is the same..)

So here we get the table of results as shown below :
Book1
ABCDEFGHIJK
9Closing Stock50039027044050035019020-160-350
10Forward Cover76543210-1-1
Sheet1
Cell Formulas
RangeFormula
B10:K10B10=MAX(SCAN(0,B6:K6,LAMBDA(a,v,a+IF(v>0,1,0))))-1


But we can see the partial week 8 is at zero, and weeks 9 & 10 now show '-1' as that '-1' is always applied to the result, even if its zero.
So, to tidy up the weeks 9, 10, I simply wrap the entire formula with an IF statement, to check if the result is greater than 0. If yes, then we give the formula result as an output. If its not (ie. result is 0 or less), then we put a '0' result in.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,180
Members
452,615
Latest member
bogeys2birdies

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