Forum Discussion
FIFO Inventory Formula Challenge
I have had the audacity to work on SergeiBaklan 's version of the solution. My reason for doing this was that I wanted to see how easy (or difficult) collaborative development might be. My first finding was that a utility that steps through the local names within a LET function returning their values one by one would be of immense value. The second conclusion is that working with someone else's LET formula is, indeed, easier than working with traditional formulas (such as we were meant to create for the present challenge).
I did make a change to Sergei's formula in that I replaced the matrix multiplication MMULT by a simpler SUM. To take the work forward I then wrapped the LET with LAMBDA to improve the parameter passing (I detest direct cell references in general and was never going to find one buried in the middle of a multi-line function appealing, despite its being appropriate to the challenge).
= LAMBDA(prNm,
LET(
type, -(EVEN(TrnType="Sale")-1),
prod, (ProductName=prNm),
table, CHOOSE({1,2,3,4},TrnNum,TrnQty*type, TrnPrice, type*prod),
total, SUM(INDEX(FILTER(table,prod),0,2)),
two, INDEX(SORT(FILTER(table, prod*type=1),,-1),{1;2},{2,3}),
price, INDEX(two,,2),
lastQty, MIN(total, INDEX(two,1,1)),
QTYs, CHOOSE({1;2}, lastQty, total-lastQty),
SUM(QTYs*price))
)(@Product)
I have yet to clarify thoughts on how the solutions to such problems might best be packaged. One option might be to output the results to a table and create a rich data type with inventory quantities and values as attributes. Another might be to use recursion to generate values for the five product lines as a single array.
I also look forward to Twifoo 's solution in due course. It does me no harm to be shown that amazing solutions can be created with traditional techniques.
As I had previously advocated, traditional formulas are accessible to more users than modern Excel functions. For that reason, my formula challenges reach the widest possible audience, rather than a privileged few.
- tbouldenFeb 10, 2021Iron Contributor
TwifooDeleted previous reply, getting used to the set-up on the forum. I've used LET below for readability and in the first cell in the attached, but left other formulas using older functions. On the right track?
=LET(
Product,"Courage",
ProdFilter,(ProductName=Product),
PurchFilter,(TrnType="Purchase"),
InventoryOnHand,SUM(CHOOSE(MATCH(TrnType,{"Purchase";"Sale"},0),1,-1)*ProdFilter*TrnQty),
LastPurchasePrice,INDEX(TrnPrice,MAX(TrnNum*PurchFilter*ProdFilter)),
LastPurchaseQty,INDEX(TrnQty,MAX(TrnNum*PurchFilter*ProdFilter)),
LastPurchaseInv,MIN(InventoryOnHand,LastPurchaseQty),
PrevPurchasePrice,INDEX(TrnPrice,LARGE(TrnNum*PurchFilter*ProdFilter,2)),
PrevPurchInv,(InventoryOnHand-LastPurchaseInv),
LastPurchaseInv*LastPurchasePrice+PrevPurchInv*PrevPurchasePrice) - TwifooFeb 10, 2021Silver Contributor
I simply adopted the adjective "traditional" mentioned by PeterBartholomew1 .
Perhaps, "traditional functions" would refer to those which are not available to non-Microsoft 365 users. Using LET is analogous to "legal cheating" for allowing the definition of names outside the Name Manager. For the purpose of my formula challenge, I will allow such, not because I allow cheating, but because it is legal.- mathetesFeb 10, 2021Silver Contributor
Twifoowrote Using LET is analogous to "legal cheating" for allowing the definition of names outside the Name Manager. For the purpose of my formula challenge, I will allow such, not because I allow cheating, but because it is legal.
That's one way of looking at LET.
I was thinking of LET more as a way of using what we often refer to as "helper columns," just that all of those "helper columns" end up being incorporated into (or referenced within) a single formula. In fact, that has given me insight into how to use LET more extensively, whenever tempted toward the "helper column" approach.
- TwifooFeb 10, 2021Silver ContributorMy analysis of the LET syntax reveals that it defines a name for the value in an argument, then use such name in the main formula. If such value, which has now been defined as a name, won't be reused in the main formula, such definition becomes superfluous!
- SergeiBaklanFeb 10, 2021Diamond Contributor
Thank you for the explanation. Still had no time to check in details, will do.
Question to your latest post, related to this case what do you mean under traditional functions? If people have LET() they shall have SORT(), FILTER(), etc. If only LAMBDA() is still exotic, but here it is only cosmetic on the top of LET().