Single Formula to acheive FIFO Costing

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
The left table (Columns A:E ) is my recent Purchase History of a product. Next, Columns G and H are my day-end Inventory Qtys. I'd like a formula in Column I that
would begin by searching the History table, in the example shown since I want the value as of 5/31/2015, I should first select (from the history table) the first date = to, or less than 5/31/2015, and in this case the 5/28/2015 row. And keep going up accumulating the full extended values, BUT no more that the Qty on Hand. In the # 5 layer I only need 586 of the 600 bought. I'm at a loss as to how to beging this formula. Can anyone assist? TIA, Jim



Excel 2012
ABCDEFGHIJKLMNOP
1
2From Layer/Series # >>54321
3Layer or** PURCHASING HISTORY **** DAY END ON HAND INVENTORY **Qty in Layer/Series >>500500600400586<< Limit total to 2,586
4Series #DateQtyExtensionU/PriceDateQtyValueU/Price Layer/Series >>$ 4.10$ 3.90$ 3.90$ 3.85$ 3.90
5105/10/20156002,340.00$ 3.900005/31/20152,586$ 10,165.40<< Need Formula to Produce20501950234015402285.4$ 10,165.40
6205/15/20154001,540.00$ 3.850006/01/20152,398which I have computed here >>
7305/20/20156002,340.00$ 3.900006/02/20152,398
8405/25/20155001,950.00$ 3.900006/03/20152,236
9505/28/20155002,050.00$ 4.100006/04/20152,686
10606/04/20155001,936.97$ 3.873906/05/20152,560
11706/07/20154501,777.12$ 3.949206/06/20152,530
12806/09/201530130.00$ 4.333306/07/20152,860
13906/14/20153201,643.07$ 5.134606/08/20152,700
141006/18/2015260950.93$ 3.657406/09/20152,531
Sheet1
Cell Formulas
RangeFormula
I5=SUM(K5:O5)
K3=C9
K4=E9
K5=K3*K4
L3=C8
L4=E8
L5=L3*L4
M3=C7
M4=E7
M5=M3*M4
N3=C6
N4=E6
N5=N3*N4
O3=H5-SUM(K3:N3)
O4=E5
O5=O3*O4
P5=SUM(K5:O5)
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Can this be done with only worksheet functions? A VBA solution would be to resize each corresponding range until the qty sum just exceeds what you have in column H, pass that to an array, subtract the excess from the last term, then sumproduct with column E.
 
Upvote 0
Yes, I'm leaning towards a UDF, utilizing like you say Resize, Array, Offset and Sumproduct ... Jim
 
Upvote 0
What industry are you in Jim?

I work in Logistics - and we average all our SKUs for the fiscal year so all our analyses are immune from price increases or payment patterns
 
Upvote 0
I'm an independent consultant, working with small businesses. I current client is a convenience Store and I'm after tracking their cigarette Inventory and also their Fuel sales.
 
Upvote 0
I'm an independent consultant, working with small businesses. I current client is a convenience Store and I'm after tracking their cigarette Inventory and also their Fuel sales.

I see.


Question: is 6/9/2015 = $9,992.99?

If I got the calculation correctly, you will need 6 layers. By June 4th your last 5 purchases will not cover the quantity on hand so you will need to tap on to the 5/10 purchase.
 
Last edited:
Upvote 0
These are the calculations I got:


If you noticed the Qty layer and Price layer rows are empty and instead nested the formula in each cell. If the calculations are correct, PM me your email and I will just send you the workbook. hth
 
Last edited:
Upvote 0
Yes, I'm leaning towards a UDF, utilizing like you say Resize, Array, Offset and Sumproduct ... Jim

I think that can work, the first number I got matched yours and z168's (but differed from the next 8):


Excel 2010
ABCDEFGHI
3Layer or** PURCHASING HISTORY **** DAY END ON HAND INVENTORY **
4Series #DateQtyExtensionU/PriceDateQtyValue
515/10/20156002,340.00$3.905/31/20152,586
625/15/20154001,540.00$3.856/1/20152,398
735/20/20156002,340.00$3.906/2/20152,398
845/25/20155001,950.00$3.906/3/20152,236
955/28/20155002,050.00$4.106/4/20152,686
1066/4/20155001,936.97$3.876/5/20152,560
1176/7/20154501,777.12$3.956/6/20152,530
1286/9/201530130$4.336/7/20152,860
1396/14/20153201,643.07$5.136/8/20152,700
14106/18/2015260950.93$3.666/9/20152,531
Sheet1 (3)


Code:
Sub fifotrack()
Dim x%, lr%, y%, qtyarray(), z%, qtyarray2(), w%
lr = Cells(Rows.Count, 1).End(xlUp).Row
For x = 5 To lr
ReDim qtyarray(0)
y = 0
z = Application.Match(Cells(x, 7), Range("b5:b" & lr), 1)
Do Until Application.Sum(Range("C" & z + 4 - y + 1 & ":C" & z + 4)) > Cells(x, 8).Value
ReDim Preserve qtyarray(y)
qtyarray(y) = Cells(z + 4 - y, 3).Value
y = y + 1
Loop
qtyarray(y - 1) = qtyarray(y - 1) - (Application.Sum(qtyarray) - Cells(x, 8).Value)
ReDim qtyarray2(y - 1)
For w = 0 To y - 1
qtyarray2(w) = qtyarray(y - 1 - w)
Next w
Cells(x, 9).Value = "=sumproduct({" & Join(qtyarray2, ";") & "}," & Range("e" & 4 + z - y + 1).Resize(y).Address & ")"
Next x
End Sub


Excel 2010
ABCDEFGHI
3Layer or** PURCHASING HISTORY **** DAY END ON HAND INVENTORY **
4Series #DateQtyExtensionU/PriceDateQtyValue
515/10/20156002,340.00$3.905/31/20152,586$10,165.40
625/15/20154001,540.00$3.856/1/20152,398$9,432.20
735/20/20156002,340.00$3.906/2/20152,398$9,432.20
845/25/20155001,950.00$3.906/3/20152,236$8,800.40
955/28/20155002,050.00$4.106/4/20152,686$10,542.35
1066/4/20155001,936.97$3.876/5/20152,560$10,050.95
1176/7/20154501,777.12$3.956/6/20152,530$9,933.95
1286/9/201530130$4.336/7/20152,860$11,247.59
1396/14/20153201,643.07$5.136/8/20152,700$10,631.59
14106/18/2015260950.93$3.666/9/20152,531$9,992.99
Sheet1 (3)
Cell Formulas
RangeFormula
I5=SUMPRODUCT({586;400;600;500;500},$E$5:$E$9)
I6=SUMPRODUCT({398;400;600;500;500},$E$5:$E$9)
I7=SUMPRODUCT({398;400;600;500;500},$E$5:$E$9)
I8=SUMPRODUCT({236;400;600;500;500},$E$5:$E$9)
I9=SUMPRODUCT({186;400;600;500;500;500},$E$5:$E$10)
I10=SUMPRODUCT({60;400;600;500;500;500},$E$5:$E$10)
I11=SUMPRODUCT({30;400;600;500;500;500},$E$5:$E$10)
I12=SUMPRODUCT({310;600;500;500;500;450},$E$6:$E$11)
I13=SUMPRODUCT({150;600;500;500;500;450},$E$6:$E$11)
I14=SUMPRODUCT({551;500;500;500;450;30},$E$7:$E$12)


z168: I only matched your first and last results. I'm assuming you calculated FIFO and perhaps more carefully looked at the changes in previous layers than I did, but why wouldn't we get the same results on 6/01/2015 for example?
 
Upvote 0
z168, thanks; I'm currently away from my office, but as soon as I can I will look into your question. Jim
 
Upvote 0
OK Guys, I think I have it. I went the UDF Route (without usage of Arrays).

Thanks for both your input on this. Jim


Excel 2012
ABCDEFGHIJK
1
2
3Layer or** PURCHASING HISTORY **** DAY END ON HAND INVENTORY **Manual Proof
4Series #DateQtyExtensionU/PriceDateQtyValue
5105/10/20156002,340.00$ 3.900005/31/20152,586$ 10,165.4010,165.40
6205/15/20154001,540.00$ 3.850006/01/20152,398$ 9,432.209,432.20
7305/20/20156002,340.00$ 3.900006/02/20152,398$ 9,432.209,432.20
8405/25/20155001,950.00$ 3.900006/03/20152,236$ 8,800.408,800.40
9505/28/20155002,050.00$ 4.100006/04/20152,686$ 10,542.3710,542.37
10606/04/20155001,936.97$ 3.873906/05/20152,560$ 10,050.9710,050.97
11706/07/20154501,777.12$ 3.949206/06/20152,530$ 9,933.979,933.97
12806/09/201530130.00$ 4.333306/07/20152,860$ 11,247.5911,247.59
13906/14/20156003,080.76$ 5.134606/08/20152,700$ 10,631.5910,631.59
141006/18/20157002,560.20$ 3.657406/09/20152,531$ 9,992.999,992.99
1506/10/20152,400$ 9,482.099,482.09
1606/11/20152,250$ 8,897.098,897.09
1706/12/20152,100$ 8,312.098,312.09
1806/13/20152,000$ 7,922.097,922.09
1906/14/20152,450$ 10,417.8510,417.85
2006/15/20152,300$ 9,832.859,832.85
2106/16/20152,200$ 9,442.859,442.85
2206/17/20152,000$ 8,646.858,646.85
2306/18/20152,500$ 10,387.0410,387.04
Sheet1
Cell Formulas
RangeFormula
D13=E13*C13
G16=G15+1
I5=ROUND(GetValue(G5,$B$5:$B$14,H5),2)
K5=SUM(D$6:D$9)+((H5-SUM(C$6:C$9))*E5)



My UDF...

Code:
Function GetValue(InvDate As Range, HistDate As Range, Qty As Long) As Single
LL = Application.Match(InvDate, HistDate, 1) + 4
Do Until AccumQty > Qty
    AccumQty = AccumQty + Cells(LL, 3).Value
    AccumSum = AccumSum + Cells(LL, 4).Value
LL = LL - 1
Loop
RAccumQty = AccumQty - Qty
AccumSum = AccumSum - (RAccumQty * Cells(LL + 1, 5))
GetValue = AccumSum
End Function
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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