简体   繁体   English

Excel公式-查找,索引匹配和组合以查找第一个匹配项

[英]Excel Formula - Lookup , Index Match Sumifs combination to find the first occurence

I have two tables that look like these: 我有两个看起来像这样的表: 在此处输入图片说明

Each order ID can appear many times without limit. 每个订单ID可以无限制显示多次。 The total sales amount in col E is the total amount of all sales with that Order ID in OrderDetail Table, so in this case total sales amount for order 122 should be 97. E行中的总销售额是OrderDetail表中具有该订单ID的所有销售额的总和,因此在这种情况下,订单122的总销售额应为97。

However, if there is ANY occurrence of "Cancel" in col J, regardless of how many times the order is made, ALL sales amount for that order ID is cancelled. 但是,如果在列J中出现“取消”的任何情况,则无论下达多少订单,该订单ID的所有销售金额都将被取消。 So for this example, the total sales amount for Order 120 and 121 should be zero, and "Cancel" status should be recorded for both Order ID in Col D. 因此,在此示例中,订单120和121的总销售额应为零,并且应在Col D中为两个订单ID记录“取消”状态。

I tried these formulas for D4 and E4, dragging them down to the end of the table. 我尝试了D4和E4的这些公式,将它们向下拖动到表格的末尾。 But as you can see, the formulas clearly don't work. 但是如您所见,这些公式显然不起作用。

D4: =INDEX($J$4:$J$11,MATCH(B4,$G$4:$G$11,0))
E4: =SUMIFS($H$4:$H$11,$G$4:$G$11,B$4,$J$4:$J$11,$J$4:$J$11<>"Cancel")

The formula can't be array formula, because both tables will keep expanding as new orders coming in. 该公式不能是数组公式,因为随着新订单的到来,两个表都将继续扩展。

Anybody can help me with this problem? 有人可以帮助我解决这个问题吗? Maybe I am missing something out, but I just can't seem to figure this out. 也许我错过了一些东西,但是我似乎无法弄清楚。 Any help would be appreciated. 任何帮助,将不胜感激。

You have a couple of issues with your ranges not matching in your formulas which could be solved by using full column references instead of just ranges. 您的公式中的范围存在一些不匹配的问题,可以通过使用完整的列引用而不只是范围来解决。 (As I'm sure Jeeped was about to suggest in the comments) (因为我确定吉普车将在评论中提出建议)

INDEX(MATCH()) is returning only the first match in your formula in D4 , you will do better with using a conditional COUNTIFS() instead: INDEX(MATCH())仅返回D4中公式中的第一个匹配项,而使用条件COUNTIFS()会更好:

=IF(COUNTIFS(J:J,"Cancel",G:G,B4)>0,"Cancel","")

There's some typos in your second formula that would be easier rectified if you use full column references, this should do the trick: 如果您使用完整的列引用,则第二个公式中有一些拼写错误会更容易纠正,这可以解决问题:

=SUMIFS(H:H,G:G,B4,J:J,"<>Cancel")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM