简体   繁体   中英

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. 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.

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. 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.

I tried these formulas for D4 and E4, dragging them down to the end of the table. 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:

=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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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