Help Please! Macro to create FIFO and LIFO functions

damonkey

New Member
Joined
Aug 5, 2015
Messages
7
Hi All,

I am trying to create a macro that would allow to perform FIFO (First In First Out) and LIFO (Last In Last Out) analysis of stock volume for a defined date period. Below is a dummy data that is set out similar to the source data.

Supplier Date Stock
a 1/01/2016 -600
b 2/01/2016 300
c 3/01/2016 1000
d 4/01/2016 600
d 5/01/2016 -200
b 6/01/2016 -500
b 7/01/2016 -100
c 8/01/2016 -300
a 9/01/2016 -100
a 10/01/2016 800
d 11/01/2016 300
a 11/02/2016 -200
a 12/01/2016 400
a 13/01/2016 -600
d 14/01/2016 -400
a 15/01/2016 800
c 16/01/2016 -600
c 17/01/2016 600
c 18/01/2016 -100

For example, having regard to this data, lets say the defined period is from 11/1/2016 and 18/1/2016. For example I will explain the answer for Supplier 'a'.

If you filter the first column for 'a' you should get the following:

Supplier Date Stock
a 1/01/2016 -600
a 9/01/2016 -100
a 10/01/2016 800
a 11/02/2016 -200
a 12/01/2016 400
a 13/01/2016 -600
a 15/01/2016 800

Now, the opening balance for supplier just before the start of the defined period (11/1/2016) is 100 (-600-100+800). Then on the next date, you sell 200 which is more than your opening balance (100), this is called short-selling. If you short-sell in the defined period, the FIFO and LIFO rules don't exactly apply and therefore this sell of 200 is going wait to be offset from a buy in the defined period.

Therefore on the next day when you buy 400, the 200 you bought yesterday offsets the 400 you bought today, therefore within the defined period you are in a net buy position of 200. Similarly, on the next day when you short-sell 600, your net position would change to short-sell of 200. Similarly, as you buy 800 the following day, this offsets your previous short-sell position and now you are back into a net buy position of 400. Overall, in both FIFO and LIFO scenarios, you end up with a net buy position of 400.

Another example with is much simpler is filtering for supplier 'c' where you should get the following:

Supplier Date Stock
c 3/01/2016 1000
c 8/01/2016 -300
c 16/01/2016 -600
c 17/01/2016 600
c 18/01/2016 -100

Now, the opening balance just prior to the defined period is 700 (1000-300). In FIFO, the 600 you sell on 16/1 offset the opening balance (700) giving you 100 opening balance left, you buy another 600 the next day and then sell 100 the following. However with FIFO, this 100 is offset against 100 leftover in the opening balance, whereas with LIFO it would be offset against the 600 you most recently bought. Therefore, with FIFO, Supplier c is in the net buy position of 600 within the defined period and with LIFO, a net buy position of 500 within the defined period.

I hope the explanations above make sense. This is too hard for me and I need some guidance/solutions because I cant seem to figure it out.
The solutions you should expect for each supplier is as below:

FIFO LIFO
a 400 a 400
b 0 b 0
c 600 c 500
d 300 d 0

I hope someone can help out with this this!
Thanks!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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