0

I want to do the following: enter image description here

The BUY and SELL area is done and ordered by date descending, but I need help to calculate the profit of each article.

What I need is to have the PROFIT Area filled like in the example.

My idea is doing it with a VLOOKUP, but I need it to use only one Transaction ID each time (one for BUY, other from SELL).

EDIT: I want all the BUY Transaction ID on "Column I" and the nearest SELL Transaction ID on his side on "Column J". If there's isn't a SELL Transaction, put only the BUY Transaction ID and leave the SELL Transaction ID in BLANK.

I hope I made myself clear.

Thanks in advance!

4

1 回答 1

1

只在你卖出时计算利润,所以我建议继续第二张表卖出:

在此处输入图像描述

如果我们使用 FIFO:先进先出,那么我们想从 BUY 表中获取第一个苹果。要获得此用途index

=INDEX(FILTER({$A$3:$A,$C$3:$C},$B$3:$B=F3),COUNTIF(F$2:F3,F3))

将此公式向下拖动。然后=G3-I3用于盈利。


对于您的区域设置,请尝试:

=INDEX(FILTER({$A$3:$A\$C$3:$C};$B$3:$B=F3);COUNTIF(F$2:F3;F‌​3))

编辑

正如@anonymous 提到的,如果您需要第一个最后一个值(最早的),则公式将按行号排序,因为您没有日期:

=INDEX(QUERY(FILTER({row($A$3:$A)\$A$3:$A\$C$3:$C};$B$3:$B=F3);"select Col2, Col3 order by Col1 desc");COUNTIF(F$2:F3,F3))

于 2017-10-02T14:25:15.440 回答