Calculate price difference on product in FIFO order

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,899
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a table in date order (oldest to newest, by day, including duplicate dates) with ledger entries for stock purchases and stock sold.

I will never sell more than what is available to sell

DateOrderProductQuantityUnit PriceUnit Price Difference (£)Unit Price Difference (%)
01/01/2019BuyA50£2
02/02/2019BuyA100£1
03/03/2019SellA-50£10??

If I need to calculate difference in price for A as £8 (£10 - £2) for date 03/01/2019, what formula would I need, based on first Buy price for Product A vs first Sell price for Product A
Related, if for 03/01/2019 -100 were sold, how would I calculate price difference as: £8.17 for Product A? £10 - (50*£2 + 10*£1)/60
And formula for % difference for same!

TIA,
Jack
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

KOKOSEK

Active Member
Joined
Apr 8, 2019
Messages
485
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
DateOrderProductQuantityUnit PriceUnit Price Difference (£)Unit Price Difference (%)
01/01/2019BuyA50£2
02/02/2019BuyA100£1
03/03/2019SellA-50£10?
If I need to calculate difference in price for A as £8 (£10 - £2) for date 03/01/2019, what formula would I need, based on first Buy price for Product A vs first Sell price for Product A

Code:
=E4-SUMIFS(E:E,A:A,MINIFS(A:A,C:C,C4))

Related, if for 03/01/2019 -100 were sold, how would I calculate price difference as: £8.17 for Product A? £10 - (50*£2 + 10*£1)/60

I think, if sold 100 --> £8.5 =10-((50*2+50*1)/100)
 

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,899
Office Version
  1. 365
Platform
  1. Windows
Thank you Kokosek,
Code:
=E4-SUMIFS(E:E,A:A,MINIFS(A:A,C:C,C4))
If more dates are added with similar data, will this formula only pull for the earliest MINIF date? I need it to work on a FIFO basis (first in, first out)

My error, meant if 60 were sold
 

KOKOSEK

Active Member
Joined
Apr 8, 2019
Messages
485
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
How do you want to solve this manually it the case if there are few deliveries on the same date (MIN date) with different price?
What your 'First Buy price' will be? Maybe it is worth to create additional column with weighted average price for each delivery date?
 

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,899
Office Version
  1. 365
Platform
  1. Windows
Happy to use a weighted average or other helper column, may need similar for quantity i.e. running total available in stock

Maximum 1 delivery per product per date. Different products can exist on matching dates.

'First Buy price' is first price for a product after it's quantity increases from 0 (assume all products quantities start at 0)

i.e.

DateOrderQuantityPrice
01/01/2019Buy100£1
02/02/2019Sell-100£10
03/03/2019Buy100£2
So in data above, 'first buy price' from 01/01/2019 - 02/02/2019 is £1

After 02/02/2019 next 'first buy price' is £2 until quantity falls back to 0

At the moment there is just a single ledger table that is meant to show change in cash and change in quantity and then margin calculations are needed from price changes over time (like table in #1)
 

KOKOSEK

Active Member
Joined
Apr 8, 2019
Messages
485
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Thank you Kokosek,
Code:
=E4-SUMIFS(E:E,A:A,MINIFS(A:A,C:C,C4))
If more dates are added with similar data, will this formula only pull for the earliest MINIF date? I need it to work on a FIFO basis (first in, first out)
If it is only 1 delivery per day First Buy date is MIN date.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,492
Messages
5,832,008
Members
430,103
Latest member
BIGGAZ

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
Top