user3423407
user3423407

Reputation: 341

How to lookup a value based on two columns (column values are not unique)

This is my data:

File1
Name School     Age    Weight
Jack St John    15
Jack St Mary    14
Jack St Michael 12
Mary St John    16
Mary St Mary    12
Mary St Michael 15

Raw data

Name School Weight
Jack St John    80
Jack St Mary    75
Jack St Michael 95
Mary St John    75
Mary St Mary    65
Mary St Michael 80

I want to fetch Weight values referring Raw data.

I tried with MATCH and INDEX, however I kept on getting #VALUE!.

Any ideas what to use to fetch these Weight values?

Upvotes: 2

Views: 727

Answers (2)

EStraka
EStraka

Reputation: 373

Here's pnuts answer laid out explicitly.

Raw data

Name    School   Weight Helper  
Jack    St John     80  Jack|St John
Jack    St Mary     75  Jack|St Mary
Jack    St Michael  95  Jack|St Michael
Mary    St John     75  Mary|St John
Mary    St Mary     65  Mary|St Mary
Mary    St Michael  80  Mary|St Michael

The formula in the helper column is:

=A2&"|"&B2 just as pnuts suggested

File1

Name    School      Age Weight
Jack    St John     15  80
Jack    St Mary     14  75
Jack    St Michael  12  95
Mary    St John     16  75
Mary    St Mary     12  65
Mary    St Michael  15  80

The formula in the Weight column is:

=INDEX('[Raw data.xlsx]Sheet1'!$C$2:$C$7,MATCH(A2&"|"&B2,'[Raw
data.xlsx]Sheet1'!$D$2:$D$7,0))

It worked first time out so I don't know why you're getting #Value.

Give credit to pnuts for this answer.

Upvotes: 1

pnuts
pnuts

Reputation: 59440

The conventional solution is to use a helper column to make the values unique. So for example in your Raw data insert a column C with =A1&"|"&B1 copied down to suit, then in File 1, D2:

=VLOOKUP(A2&"|"&B2,'Raw data'!C:D,2,0)  

copied down to suit.

Upvotes: 4

Related Questions