Finding Oldest value to make up specified sum

sriche01

Board Regular
Joined
Dec 24, 2013
Messages
136
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I'm working on a first in first out orders vs inventory spreadsheet.

ABCDEFG
1CropItemQtyItemOrder DateQty
21A10A1/1/201950
34A20A1/2/201930
46A30A1/3/201990
58A40A1/4/201970
610A50A1/5/201940
713A60A1/6/2019100
812A70A1/7/201980
915A80A1/8/201910
1011A90A1/9/201920
1114A100A1/10/201960
122B5B1/11/201932
135B8B1/12/201925
147B25B1/13/201916
159B32B1/14/20198
163C16C1/15/20195

<tbody>
</tbody>
Sheet1


So hopefully this simplified sample data will work.
Inventory Data
Columns A,B,C Represent inventory data with a crop serial number (column A), Item Number (column B) and crop quantity (Column C).
Crop serial numbers (column A) are unique and are date based so that lower number means earlier date = older crop.

Order Data
Columns E, F G are orders we have against the inventory in the first three columns.
Again, we have Item number (column E), Ship date (column F), Quantity ordered (column G)

My goal is to identify the oldest crop number that will have a quantity available for a given order if we fill these orders using oldest crops to fill earliest orders for a given item.

So for the order for Item A going out on 1/6/19, my desired formula would return "12" because all crops of Item A Older than (lower crop number than) 12 are needed for earlier shipping orders. (Adding all orders before 1/6 totals 280. Crops before 12 for column A total 240)

The orders and the Inventory are actually on separate sheets of the same workbook and are different lengths.
Neither the orders nor the crops will always be sorted by date. There are some dates where multiple orders of the same item will ship. At this point I am just looking for the oldest crop that will have any inventory left at a given order date before anything ships on that date.

Somehow I feel like I've done something like this before, but can't quite put my finger on it...

Thanks in advance!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Ok, Let's see if I can simplify this...

EFGHI
1ItemOrder DateQtyQty availableOldest Crop Number
2A1/1/201950550
3A1/2/201930460

<tbody>
</tbody>


ABC
1CropItemQty
21A10
34A20
46A30
58A40
610A50
713A60
812A70
915A80
1011A90
1114A100
122B5
135B8
147B25
159B32
163C16

<tbody>
</tbody>
Sheet2
What I really want is to identify the oldest crop available to make up a specified sum.

The crop numbers in Table 2, column A are exclusive and age related - the lower the number, the older the crop of a particular Item. So to start the year, we have a total of 550 "A" Items on inventory. That appears in column H of table 1. All 550 are available to pull for this first order. The second order of "A" items only has 460 to choose from because the first order is presumably gone.

What I want is to identify in column I the oldest (smallest) crop number that will still have inventory left in it by the time we get to the ship date for any given order. Now, we may have multiple orders of the same item going out on the same date, but we'll deal with that later. I simply want to match the oldest available crop with inventory in it to an order date.

Any ideas?

Thanks!
 
Upvote 0
Maybe:

ABCDEFGHI
1CropItemQtyItemOrder DateQtyEarliest Batch with available qty
21A10A1/1/2019501
34A20A1/2/2019306
46A30A1/3/2019908
58A40A1/4/20197011
610A50A1/5/20194012
713A60A1/6/201910012
812A70A1/7/20198014
915A80A1/8/20191014
1011A90A1/9/20192015
1114A100A1/10/20196015
122B5B1/11/2019322
135B8B1/12/2019257
147B25B1/13/2019169
159B32B1/14/20198Not available
163C16C1/15/201953

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
H2{=IFERROR(SMALL(IF(SUMIFS($C:$C,$B:$B,E2,$A:$A,"<="&ROW(INDIRECT("1:20")))>SUMIFS($G:$G,$E:$E,E2,$F:$F,"<"&F2),ROW(INDIRECT("1:20"))),1),"Not available")}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



The INDIRECT("1:20") represents the upper number of crops you have.
 
Upvote 0
The INDIRECT("1:20") represents the upper number of crops you have.

Thanks, Eric, for helping me with this. So if I am understanding right, the 1:20 just assumes I have 20 or fewer crop lines for a given item, or does it mean the serial numbers themselves are lower than 20?

My actual crop numbers are 6 digits long. I just used small numbers for simplicity. But I would be well within the 20 crops available parameter...
 
Upvote 0
If the lowest serial number in your list is 123456, and the highest is 234567, then use INDIRECT("123456:234567"). You'd want to use the smallest range you can, since the more numbers the formula has to check, the slower the formula will be.
 
Upvote 0
If the lowest serial number in your list is 123456, and the highest is 234567, then use INDIRECT("123456:234567"). You'd want to use the smallest range you can, since the more numbers the formula has to check, the slower the formula will be.

Thanks, just got it working using a minifs and maxifs to set the range. Works Great! Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,853
Members
449,194
Latest member
HellScout

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