FIFO based on date only...

Another User

New Member
Joined
Jan 4, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Good morning everyone,
I've spent nearly a whole day on this but can't seem to get it right...

I'm trying to make a running spreadsheet that works on the FIFO principles, but with the same unit costs. The issue is that the status of the goods changes from "Certified" no "non-certified" after 24 months. I thought it was pretty straightforward, but can't get a formula to work. I think I must be getting into VBA territory now. Please see image below.
If I put a sale in the output column for the month, it needs to come off the "Credit Balance". Data is entered into the shaded columns only...
1641339986466.png
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
AnotherUser.xlsb
ABCDEFGH
1monthinput 100%CSsalestrasheffective salesbalanceaverage age (months)paternoster
2jan-18100001001,0/ / / / / / / / / / / / / / / / / / / / / / / / / 100
3feb-18100002001,5/ / / / / / / / / / / / / / / / / / / / / / / / 100/ 100
4mrt-18100003002,0/ / / / / / / / / / / / / / / / / / / / / / / 100/ 100/ 100
5apr-18100004002,5/ / / / / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100
6mei-18100005003,0/ / / / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100
7jun-18100006003,5/ / / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100
8jul-18100007004,0/ / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100
9aug-1810010001007004,0/ / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100
10sep-18100008004,5/ / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
11okt-18100009005,0/ / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
12nov-18100001.0005,5/ / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
13dec-1810015001509505,3/ / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
14jan-19100001.0505,8/ / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
15feb-19100001.1506,3/ / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
16mrt-191001.00001.0002501,8/ / / / / / / / / / / / / / / / / / / / / / / 50/ 100/ 100
17apr-19100003502,3/ / / / / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100
18mei-19100004502,8/ / / / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100
19jun-19100005503,3/ / / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100
20jul-19100006503,8/ / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100
21aug-19100007504,3/ / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100
22sep-19100008504,8/ / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
23okt-19100009505,3/ / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
24nov-1910090009001501,3/ / / / / / / / / / / / / / / / / / / / / / / / 50/ 100
25dec-19100002501,8/ / / / / / / / / / / / / / / / / / / / / / / 50/ 100/ 100
26jan-20100003502,3/ / / / / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100
27feb-20100004502,8/ / / / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100
28mrt-20100005503,3/ / / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100
29apr-20100006503,8/ / / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100
30mei-20100007504,3/ / / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100
31jun-20100008504,8/ / / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
32jul-20100009505,3/ / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
33aug-20100001.0505,8/ / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
34sep-20100001.1506,3/ / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
35okt-20100001.2506,8/ / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
36nov-20100001.3507,3/ / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
37dec-2010050005009505,3/ / / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
38jan-21100001.0505,8/ / / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
39feb-21100001.1506,3/ / / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
40mrt-21100001.2506,8/ / / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
41apr-21100001.3507,3/ / / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
42mei-21100001.4507,8/ / / / / / / / / / / 50/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
43jun-211001.70001.55000,0/ / / / / / / / / / / / / / / / / / / / / / / / /
44jul-21100001001,0/ / / / / / / / / / / / / / / / / / / / / / / / / 100
45aug-21100002001,5/ / / / / / / / / / / / / / / / / / / / / / / / 100/ 100
46sep-21100003002,0/ / / / / / / / / / / / / / / / / / / / / / / 100/ 100/ 100
47okt-21100004002,5/ / / / / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100
48nov-21100005003,0/ / / / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100
49dec-21100006003,5/ / / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100
50jan-22100007004,0/ / / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100
51feb-22100008004,5/ / / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
52mrt-22100009005,0/ / / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
53apr-22100001.0005,5/ / / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
54mei-22100001.1006,0/ / / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
55jun-22100001.2006,5/ / / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
56jul-22100001.3007,0/ / / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
57aug-22100001.4007,5/ / / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
58sep-22100001.5008,0/ / / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100
59okt-22101001.6018,5/ / / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101
60nov-22102001.7039,0/ / / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102
61dec-22103001.8069,5/ / / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103
62jan-23104001.91010,0/ / / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104
63feb-23105002.01510,4/ / / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105
64mrt-23106002.12110,9/ / / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105/ 106
65apr-23107002.22811,4/ / / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107
66mei-23108002.33611,9/ / / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107/ 108
67jun-23109002.44512,3/ / 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107/ 108/ 109
68jul-23110002.55512,8/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107/ 108/ 109/ 110
69aug-2311110002.56612,8/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107/ 108/ 109/ 110/ 111
70sep-2311210002.57812,7/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107/ 108/ 109/ 110/ 111/ 112
Blad2
Cell Formulas
RangeFormula
A2:A70A2=IF(ROW()=2,DATE(2018,1,1),EDATE(OFFSET(A2,-1,,,),1))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:C70Expression=-C2<>-E2textNO
 
Upvote 0
VBA Code:
Public Dict, lStock, lTrash, Result(), iRij, DBR

Sub MyFifo()
     Application.ScreenUpdating = False
     Set Dict = CreateObject("scripting.dictionary")
     For ptr = 1 To 25
          Dict(ptr) = Array(ptr, 0)
     Next
     Set DBR = Sheets("blad2").ListObjects(1).DataBodyRange
     a = Sheets("blad2").ListObjects(1).DataBodyRange.Resize(, 3).Value2     'read first 3 columns
     ReDim Result(1 To UBound(a), 1 To 10)
     For iRij = 1 To UBound(a)
          DoEvents
          datum = CDbl(a(iRij, 1))
          Dict.Add datum, Array(datum, a(iRij, 2))
          MaxSizeDictionary
          Sales CInt(a(iRij, 3))

          DBR.Offset(, 3).Resize(UBound(Result), UBound(Result, 2)).Value = Result
     Next


End Sub

Sub MaxSizeDictionary()
     a = Application.Sort(Application.Index(Dict.items, 0, 0), 1)
     r = UBound(a) - 25
     lTrash = 0
     For i = 1 To r
          lTrash = lTrash + a(i, 2)
          Dict.Remove (a(i, 1))
     Next
     Result(iRij, 1) = lTrash

End Sub

Sub Sales(QTY)
     qty0 = QTY
     a = Application.Sort(Application.Index(Dict.items, 0, 0), 1)
     For i = 1 To UBound(a)
          qty1 = Application.Min(qty0, a(i, 2))
          If qty1 > 0 Then Dict(a(i, 1)) = Array(a(i, 1), a(i, 2) - qty1): qty0 = qty0 - qty1
          If qty0 <= 0 Then Exit For
     Next
     Result(iRij, 2) = QTY - qty0

     a = Application.Transpose(Application.Index(Dict.items, 0, 2))
     Result(iRij, 3) = Application.Sum(a)
     If Result(iRij, 3) = 0 Then
          Result(iRij, 4) = 0
     Else
          Weight = [transpose(26-row(1:25))]
          Result(iRij, 4) = WorksheetFunction.SumProduct(Weight, a) / Result(iRij, 3)
     End If

     For i = 1 To UBound(a): Result(iRij, 5) = Result(iRij, 5) & "/" & Right(WorksheetFunction.Rept(" ", 5) & Format(a(i), "#,###"), 5): Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,814
Messages
6,121,711
Members
449,049
Latest member
THMarana

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