Forum Discussion
Using FIFO to Determine Sale Price of Fuel
- Sep 20, 2022
Now the formula with a mixed price.
Hello! You could use a function without VBA. XLOOKUP allows you to search for the next largest match. For this, I need an auxiliary column in which the purchased quantities are listed cumulatively. Have a look at the solution in the attached sheet to see if it meets your requirements.
- dscheikeySep 20, 2022Bronze Contributor
What should the price be when the price changes. A mixed price?
3/16/2022 12:59:00 PM 520 607 1.4023 3/16/2022 1:07:00 PM 608 275 1.3936 3/16/2022 3:47:00 PM 546 280 1.3913 - mandyturcotteSep 20, 2022Copper ContributorI think a mixed price is probably the best/easiest way to accomplish it.
- PeterBartholomew1Sep 20, 2022Silver Contributor
This is a technically far more complicated solution using advanced features of Excel 365.
salesPrice = LET( cumPurchases, SCAN(0,purchaseQuantity, Sumλ), cumSales, SCAN(0, quantitySold, Sumλ), MAP(cumSales-quantitySold, cumSales, LAMBDA(s₀,s₁, SUM( MAP(purchasePrice, cumPurchases-purchaseQuantity, cumPurchases, LAMBDA(pr,v₀,v₁, MAX(MIN(v₁,s₁)- MAX(v₀,s₀),0)* pr ) ) ) / (s₁-s₀) ) ) );
The formula accumulates both sales and purchase volumes. Then it calculates the overlaps and the price of each tranche. The unit price is obtained by dividing by the sales quantity.
As the sales quantities are small relative to the purchase quantities, very few sales actually require an interpolated price calculation.