How can I lookup when match has more than one value?

B

bonot1

I am using LOOKUP functions to retrieve info from a list. Some of the lookup
values have more than one match in the list. Is there a function that allows
me to retrieve multiple elements for one lookup value, or at least a function
that tells me there are duplicate matches?
 
D

David Hilberg

=IF( CountIf(a1:a10,"Joe")<>1, CountIf(a1:a10,"Joe"),
LookUp(..etc...) )

will give you the count if there are more or fewer than one.
Otherwise, it performs the lookup.

- David
 
T

T. Valko

Is the data sorted so that the lookup_values are grouped together or is the
data random? Is the data to be returned text or numeric?
 
B

bonot1

This is helpful and I will think on this, but in my case nearly all of the
CountIfs will be greater than 1. To use your example, I may have 10
instances of "Joe" in my list; the lookup against "Joe" might return "abc" or
"cde". Most Joe, Pam, etc. have only one value "abc" as their match, but
some Joe, Pam, etc. have both "abc" and "cde". I need a way to know that.
 
T

T. Valko

Here's one way:

Assume data in A2:B20. You want to extract data from column B that
corresponds to a lookup_value.

D2 = lookup_value

Array entered** :

=IF(ROWS($1:1)<=COUNTIF(A$2:A$20,D$2),INDEX(B$2:B$20,SMALL(IF(A$2:A$20=D$2,ROW(B$2:B$20)-MIN(ROW(B$2:B$20))+1),ROWS($1:1))),"")

Copy down until you get blanks.

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER)
 
B

bonot1

Thanks. I am working with your suggestion, but I am not sure if I expressed
my problem clearly.

Using your example, in A2:A20 there would be say three different values
"abc", "cde", and "efg". When I lookup in B2:B20, there is a "123" for every
"abc", a "345" for every "cde"; VLOOKUP works fine for these. However, rows
with "efg" in column A sometimes have "789" in column B and sometimes have
"567".

What I need is to 1) be made aware that "efg" has two different matches in
column B, and 2) know what the values of those two matches are. This is what
I would like to automate.
 
T

T. Valko

Well, then all you need to do is test for the presence of those 2 values
that correspond to "efg". I have a feeling that your sample data is "fake"
so any formula I suggest might not work on your real data since the formula
is based on your explanation. Anyhow, try this:

=IF(COUNTIF(A$2:A$20,"efg"),IF(AND(COUNTIF(B$2:B$20,567),COUNTIF(B$2:B$20,789)),INDEX({567,789},ROWS($1:1)),IF(ROWS($1:1)=1,VLOOKUP("efg",A$2:B$20,2,0),"")),"")

Copy to a total of 2 cells.
 
F

farhad

I am using LOOKUP functions to retrieve info from a list. Some of the lookup
values have more than one match in the list. Is there a function that allows
me to retrieve multiple elements for one lookup value? Offcourse the data is
in random order, and the data to be returned is text. I need to have all the
records that lookup retrieve it on the same rows.
 
F

farhad

I am using LOOKUP functions to retrieve info from a list. Some of the lookup
values have more than one match in the list. Is there a function that allows
me to retrieve multiple elements for one lookup value? Offcourse the data is
in random order, and the data to be returned is text. I need to have all the
records that lookup retrieve it on the same rows.
 
N

Niek Otten

Look here:

http://office.microsoft.com/en-us/excel/HA012260381033.aspx

Unfortunately, the formulas are truncated. But the text explains very well what to do, so hopefully you can manage.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

|I am using LOOKUP functions to retrieve info from a list. Some of the lookup
| values have more than one match in the list. Is there a function that allows
| me to retrieve multiple elements for one lookup value? Offcourse the data is
| in random order, and the data to be returned is text. I need to have all the
| records that lookup retrieve it on the same rows.
|
 
A

Alan Beban

farhad said:
I am using LOOKUP functions to retrieve info from a list. Some of the lookup
values have more than one match in the list. Is there a function that allows
me to retrieve multiple elements for one lookup value? Offcourse the data is
in random order, and the data to be returned is text. I need to have all the
records that lookup retrieve it on the same rows.
If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook you might
want to consider the VLookups function. It is designed for this purpose.

Alan Beban
 
A

Alfonso Valdes

Hi I have a huge list of data that has items and each item has different
specifications. For example:


36134008 R AA Z34116-1
36153004 R AA Z33021-1
34377007 P AA Z28031-1
34377007 P ZZ 5313312
34377007 P ZZ 4758766
36321027 P AA Z00000-1
36321027 P AA Z30918-1
36416003 P AA X32118-1
36421026 P ZZ 2394200

What I want to do is use a vlookup(34377007,$A$1:$B$8,4,FALSE)
The output that this vlookup will give me would be "Z28031-1" but in some
cases I want the information of the second row"5313312" or maybe the
third"4758766".
I have seen that there is explanations, and formulas that give you all the
info like this:
34377007 Z28031-1
5313312
4758766
But for the purpose of what i am doing I do not need all the values I just
need one of them.


for example:

Same vlookup, but I want the formula to give me the info from the second row
when it found the first value that match the vlookup

I do not know if exist a formula that makes this
vlookup(34377007,$A$1:$B$8,4(row2),FALSE)
=“5313312â€

36134008 R AA Z34116-1
36153004 R AA Z33021-1
34377007 P AA Z28031-1
34377007 P ZZ 5313312
34377007 P ZZ 4758766
36321027 P AA Z00000-1
36321027 P AA Z30918-1
36416003 P AA X32118-1
36421026 P ZZ 2394200






Same vlookup, but I want the formula to give me the info from the third row
when it found the first value that match the vlookup.
Vlookup (34377007, $A$1:$B$8, 4(row3),FALSE)
=“4758766â€

36134008 R AA Z34116-1
36153004 R AA Z33021-1
34377007 P AA Z28031-1
34377007 P ZZ 5313312
34377007 P ZZ 4758766
36321027 P AA Z00000-1
36321027 P AA Z30918-1
36416003 P AA X32118-1
36421026 P ZZ 2394200
 
T

T. Valko

If your data table is sorted or grouped together as is shown in your sample:

A2:D10 = data table

F2 = lookup value = 34377007
G2 = instance number = 2

=INDEX(D2:D10,MATCH(F2,A2:A10,0)+G2-1)

Result = 5313312
 
M

MRLYONS68

I have also tried to use this article, but I am getting "#NUM" error values
using the "SMALL" mixed with the "ROW" functions. I am following the example
verbatim, and I do not think this should be that difficult. This article
attempts to do EXACTLY what I am looking for.

Does anyone know of where the actual example can be downloaded as some of
the formulas are truncated?

Regards,

Mike
 
H

Hijosdelongi

Hi,

I have a Question.. if VLOOKUP plus IF possible? This is my fomula..

=VLOOKUP(IF((Data!A1:A1000=A1)*(Data!B1:B1000=D1),....

Can you help me with this..

THank you.
 
H

Hijosdelongi

Hi,

I have a Question.. is VLOOKUP plus IF possible? This is my fomula..

=VLOOKUP(IF((Data!A1:A1000=A1)*(Data!B1:B1000=D1),....

is my logical tests or conditions correct? and how will i put the VLOOKUP
codes?

Can you help me with this..

THank you so much
 
T

T. Valko

Where is the data you want returned?

What is the data type of the value to be returned? Is it text? Numeric?

When there are multiple lookup_values you would typically use an array
formula** like this:

=INDEX(Data!C1:C10,MATCH(1,(Data!A1:A10=A1)*(Data!B1:B10=D1),0))

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the SHIFT
key then hit ENTER.
 
H

Hijosdelongi

Actually the data that i want to be returned is both numeric and text thats
why i had IF function.. in a typical VLOOKUP formula is should be like this..

=VLOOKUP(B1,Data!A1:A1000,2,FALSE)

but since i only want to have the data that is equivalent to the date and
the name on the database thats why im to use this formula..

=VLOOKUP(IF((Data!A1:A1000=A1)*(Data!B1:B1000=D1),....

that is also why im having problems in how to formulate the conditions in
the IF function and how to get the data using the VLOOKUP.

I hope you can help me.

Thank you so much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top