Ordered Subtraction/Addition by Dates Until Reaching Given Value

alexb523

Board Regular
Joined
Dec 12, 2013
Messages
115
Hello & Sorry for the confusing title,

I am trying to do following in less steps (preferably one step). I will first explain what I need to be done, then how i am currently doing it.


I need to find out what week/date my "CurrentLevel" will hit (be equal to or below) my "LowestLevel" allowed based on two other tables which represent product coming in and demand for the product (product going out). These two tables (in tabular format) have dates associated with them and will effect when the "CurrentLevel" hits the "LowestLevel".

So, I could have 200 apples coming in but at separate times. 50 coming in next week, 50 coming in three weeks from now, etc. In addition, there is the reverse effect on demand. I could have 10 going this week, 30 going out the following week, etc.

I tried to represent these two tables below with "In" & "Out" columns.

wk range = 1 - 10 but i am working with actual dates that can go into next year etc.


Currently, pivot both to put into a matrix and then use another table and index-matches each in & out matrix to get the difference of what is happening that week for that product. Then I use another table that starts off at my currently level, use and index-match on the difference table and then, finally, I use that table and index-match when it is below the current stock value.

I am hoping there is just one grand formula I can use, or weed out some the step to get this info.

I tried my best to explain it here. If there is any confusion, please let me know.

Thanks!
alexb


Tables are below:


ProductLowestLevelCurrentLevel
apples50122
oranges150190
peachs2556
watermelon3295

<colgroup><col><col><col></colgroup><tbody>
</tbody>


ProductQtyIn (wk #)
apples505
peaches1010
apples501
peaches103
peaches109
peaches102
oranges1005
peaches107
oranges1004
watermelon759
watermelon755
watermelon753
apples507

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>


ProductQtyOut (wk #)
apples101
apples202
apples353
apples274
apples235
apples86
apples457
apples78
apples189
apples1210
peaches51
peaches122
peaches103
peaches64
peaches125
peaches126
peaches147
peaches68
peaches79
peaches1210
oranges251
oranges242
oranges303
oranges324
oranges155
oranges306
oranges357
oranges158
oranges259
oranges2610
watermelon351
watermelon322
watermelon333
watermelon274
watermelon355
watermelon256
watermelon357
watermelon288
watermelon289
watermelon2310

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Your explanation is fine. Your solution is too convoluted. :)

Here's how I would solve it -- and how I tested it. It's easy to implement, easy to understand, easy to maintain, and lets Excel do all the heavy lifting.

Convert each of your ranges to a table (as Excel understands it). Note that Excel gives each table an unique name. In my case the names were:
Out table: Table1,
In table: Table2,
CurrentLevel (and lowestlevel) table: Table3, and
the new table I mention below: Table 15.

This is relevant because you will have to adjust my formulas depending on the table names in your worksheet.

For the In and the Out tables add a column, called Key, that combines the product and week.
Code:
=[@Product]&CHAR(255)&[@[Out (wk '#)]]
and
Code:
=[@Product]&CHAR(255)&[@[In (wk '#)]]

In the table with current and lowest levels, add a column (call it LowestZeroRel) with the formula
Code:
=[@CurrentLevel]-[@LowestLevel]

Now, add a new table that has the product and week numbers of interest. I used the values from your 'Out' table (the headers for the 2 columns in this new table are Product and Wk).

Now, add 4 calculated columns: Key, Out, In, and Net. The formulas:
Code:
=[@Product]&CHAR(255)&[@Wk]
Code:
=INDEX(Table1[Qty],MATCH([@Key],Table1[Key],0))
Code:
=IFERROR(INDEX(Table2[Qty],MATCH([@Key],Table2[Key],0)),0)
and
Code:
=IF(OFFSET([@Product],-1,0)=[@Product],OFFSET([@Net],-1,0),INDEX(Table3[LowestZeroRel],MATCH([@Product],Table3[Product],0)))+[@In]-[@Out]

Now, go back to the CurrentLevel table and add a column . Name this column 'Wk Out'. The formula should be the *array* formula
Code:
=MIN(IF((Table15[Net]<=0)*(Table15[Product]=[@Product]),Table15[Wk]))

To enter an array formula complete data entry with CTRL+SHIFT+ENTER rather than just the ENTER or TAB key. If done correctly, *Excel* will show the formula in curly brackets { and }

A value of zero in this column means you will never hit the 'Lowest Level' threshold. Any value > 0 is the week when you do hit the threshold.


Hello & Sorry for the confusing title,

I am trying to do following in less steps (preferably one step). I will first explain what I need to be done, then how i am currently doing it.


I need to find out what week/date my "CurrentLevel" will hit (be equal to or below) my "LowestLevel" allowed based on two other tables which represent product coming in and demand for the product (product going out). These two tables (in tabular format) have dates associated with them and will effect when the "CurrentLevel" hits the "LowestLevel".

So, I could have 200 apples coming in but at separate times. 50 coming in next week, 50 coming in three weeks from now, etc. In addition, there is the reverse effect on demand. I could have 10 going this week, 30 going out the following week, etc.

I tried to represent these two tables below with "In" & "Out" columns.

wk range = 1 - 10 but i am working with actual dates that can go into next year etc.


Currently, pivot both to put into a matrix and then use another table and index-matches each in & out matrix to get the difference of what is happening that week for that product. Then I use another table that starts off at my currently level, use and index-match on the difference table and then, finally, I use that table and index-match when it is below the current stock value.

I am hoping there is just one grand formula I can use, or weed out some the step to get this info.

I tried my best to explain it here. If there is any confusion, please let me know.

Thanks!
alexb


Tables are below:


ProductLowestLevelCurrentLevel
apples50122
oranges150190
peachs2556
watermelon3295

<colgroup><col><col><col></colgroup><tbody>
</tbody>


ProductQtyIn (wk #)
apples505
peaches1010
apples501
peaches103
peaches109
peaches102
oranges1005
peaches107
oranges1004
watermelon759
watermelon755
watermelon753
apples507

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>


ProductQtyOut (wk #)
apples101
apples202
apples353
apples274
apples235
apples86
apples457
apples78
apples189
apples1210
peaches51
peaches122
peaches103
peaches64
peaches125
peaches126
peaches147
peaches68
peaches79
peaches1210
oranges251
oranges242
oranges303
oranges324
oranges155
oranges306
oranges357
oranges158
oranges259
oranges2610
watermelon351
watermelon322
watermelon333
watermelon274
watermelon355
watermelon256
watermelon357
watermelon288
watermelon289
watermelon2310

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,128,035
Members
449,414
Latest member
sameri

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