Weighted average when item inventory reaches zero (Excel)

huangapple go评论55阅读模式
英文:

Weighted average when item inventory reaches zero (Excel)

问题

我有一个包含交易数据的Excel工作表(示例图像),在加权平均方面遇到了问题。问题发生在项目完全售出/卸载后,当再次购买时,计算会包括先前已售出的项目的旧价格信息。我可能需要使用一个函数,在特定项目达到零并以新价格再次购买后“重新启动”加权平均计算。我不知道如何做到这一点,或者是否在Excel中可能。我真的很感激任何想法或帮助!

Weighted average when item inventory reaches zero (Excel)

目前使用的公式是:

Col H =SUMIFS($F$2:F2; $D$2:D2; D2)

Col I =IF(B2="Buy";SUMPRODUCT(--($C$2:C2=C2); --($B$2:B2="Buy");$E$2:E2;$F$2:F2)/SUMIFS($F$2:F2;$C$2:C2;C2;$B$2:B2;B2);" ")

英文:

I have an excel worksheet containing transaction data (example image) and ran into a problem with weighted averages. The problem occurs after an item is fully sold/unloaded when it is bought again, the calculation includes the old price information of the items that were previously sold. I would probably need to use a function that "restarts" calculating the weighted average after the position reached zero for a specific item and is bought again at a new price. I do not know how to do this or if this is possible in Excel at all. I would really appreciate any ideas or help!

Weighted average when item inventory reaches zero (Excel)

Formulas currently used are:

Col H =SUMIFS($F$2:F2; $D$2:D2; D2)

Col I =IF(B2="Buy";SUMPRODUCT(--($C$2:C2=C2); --($B$2:B2="Buy");$E$2:E2;$F$2:F2)/SUMIFS($F$2:F2;$C$2:C2;C2;$B$2:B2;B2);" ")

答案1

得分: 1

=IF(H2=0,"-",
IFERROR(LET(prevZero,XMATCH(1,(H1:H$1=0)*(C1:C$1=C2),0,-1)+1,
SUMIFS(INDEX(G:G,prevZero):G2,INDEX(C:C,prevZero):C2,C2)/SUMIFS(INDEX(H:H,prevZero):H2,INDEX(C:C,prevZero):C2,C2)),
SUMIFS(G$2:G2,C$2:C2,C2)/H2))

assuming all items are sold in one transaction as in your sample data.

Another way of looking it which agrees with your idea is that for buy transactions:

New average = (Previous average * previous number of items on hand + Current price * number of items purchased) / Current number of items on hand

while for sell transactions the number of items on hand is updated but the average price is just carried forward.

This actually gives a simpler formula:

=IF(H2=0,0,
IFERROR(LET(prevTrans,XMATCH(TRUE,C1:C$1=C2,0,-1),
IF(B2="Sell",INDEX(J:J,prevTrans),(INDEX(H:H,prevTrans)*INDEX(J:J,prevTrans)+G2)/H2)),
E2))

英文:

If you are able to use xmatch, you can search back for a previous occurrence of a zero and only include transactions after that:

=IF(H2=0,"-",
IFERROR(LET(prevZero,XMATCH(1,(H1:H$1=0)*(C1:C$1=C2),0,-1)+1,
SUMIFS(INDEX(G:G,prevZero):G2,INDEX(C:C,prevZero):C2,C2)/SUMIFS(INDEX(H:H,prevZero):H2,INDEX(C:C,prevZero):C2,C2)),
SUMIFS(G$2:G2,C$2:C2,C2)/H2))

Weighted average when item inventory reaches zero (Excel)

assuming all items are sold in one transaction as in your sample data.

Another way of looking it which agrees with your idea is that for buy transactions:

New average = (Previous average * previous number of items on hand + Current price * number of items purchased) / Current number of items on hand

while for sell transactions the number of items on hand is updated but the average price is just carried forward.

This actually gives a simpler formula:

=IF(H2=0,0,
IFERROR(LET(prevTrans,XMATCH(TRUE,C1:C$1=C2,0,-1),
IF(B2="Sell",INDEX(J:J,prevTrans),(INDEX(H:H,prevTrans)*INDEX(J:J,prevTrans)+G2)/H2)),
E2))

Weighted average when item inventory reaches zero (Excel)

I have added a new item C which ends up with an average price of $15 for the 100 remaining units as required.

huangapple
  • 本文由 发表于 2023年6月29日 13:02:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578172.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定