Home » excel » Excel Formula – Lookup , Index Match Sumifs combination to find the first occurence

Excel Formula – Lookup , Index Match Sumifs combination to find the first occurence

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have two tables that look like these:
enter image description here

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.

How to&Answers:

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