Multi-Criteria Lookups

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
Hmm, one thing that I haven't seen around is Multi-Criteria Lookups... I was driven to demonstrate how to do one in a contest of one-upmanship a few weeks back, and it's sorta been rolling around in my head since then. In that particular thread, my formula was flawed, since Lookup() needs the search vector to be ascending alphabetical... but for the gist of that thread, it didn't much matter anyway. I'm surprised that Chip doesn't cover the topic in his Lookup Article. Was wondering if other people have seen this around, and I just missed it.
Csacading_List.xls
FGHIJK
7tomchevy10pollychevy
8****ford20130
9harrypontiac30
10janesubaru40
11pollyamc50
12kelleyvolvo60
13scottchevy70
14brianford80
15tompontiac90
16****subaru100
17harryamc110
18janevolvo120
19pollychevy130
20kelleyaztek140
21paulpontiac150
22briansubaru160
23tomamc170
24****volvo180
25harrychevy190
Sheet1
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
It's not transparent to me that what you're solving is any more simple than this:

=SUMPRODUCT(-(A1:A19=E1),-(B1:B19=F1),(C1:C19))

Not to mention that this takes into account for multiple returns.

Or for looking up:

{=INDEX(C1:C19,MATCH(1,(A1:A19=E1)*(B1:B19=F1),0))}

I changed your ranges to line up with A1 and so forth.

Concatenation is a pretty expensive operation and you're doing quite a bit of it. Without testing the performance, I would guess it drags. Do you know how well this performs?
 
Of course SUMPRODUCT's only good for numeric results. You can use LOOKUP, without CSE and without sorting, e.g.

=LOOKUP(2,1/((A1:A19=E1)*(B1:B19=F1)),C1:C19)

although this works slightly differently to Nate's suggested INDEX/MATCH because it'll find the last match not the first.
 
As Barry pointed out, the Sumproduct() option doesn't work for non-numeric data. In contriving the data, I overlooked the Sumproduct() option that my numeric column allowed, even though I had a Lookup style solution in mind from the start.

I hadn't bothered to test performance of the concatenation approach... I wouldn't be surprised to find that it's quite expensive.

Between the Index() versus Lookup() solutions to this, the former is slightly more intuitive to me, though both solutions are building a lookup array in a similar fashion. I had to examine the Lookup() solution more closely before I realized why the Div by Zero results are preferable to 1's. If only a single match is expected, I'm not sure that either method has a benefit ove rthe other... though I could envision comparing the results of the two to determine if more than one match exists.

Thank you both for showing me a better way. :bow: Outside of Sumproduct(), building an array by coercing numeric results from boolean comparisons is still not as intuitive to me as it is to you guys, but every time I get exposed to it in other applications, it makes a deeper impression. Maybe there's hope for me yet!
 
Right, I didn't mean to imply that Sumrproduct() is good for pure-play Lookups in general, I just noted it would work with your specific data set. Which is why I provided the 2nd construct, as I knew that's what you really after.

You are welcome. :)
 

Forum statistics

Threads
1,222,682
Messages
6,167,604
Members
452,122
Latest member
Warwick89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top