# Two Way Lookup in Excel

In Excel, we have the VLOOKUP function to perform Lookup in Vertical direction (Rows) and the HLOOKUP function to Lookup in Horizontal direction (Columns).

But for 2 Way Lookup? i.e. to perform Lookup in both columns and rows?

No. Excel doesn’t have a dedicated function for this purpose. We should create the formula for 2 Way Lookup using the available Excel functions.

This tutorial is about 3 different formulas which can be used to perform Two Way Lookup in Excel.

Following is the data set used for this purpose and our aim to find the Marks scored by ‘Hana’ for her ‘Computer’ exam.

### 2 Way Lookup using XLOOKUP function

Nesting the XLOOKUP function inside another is one of the fastest ways to perform 2 Way Lookup in Excel.

The following formula will return the marks scored by Hana for her Computer exam.

`=XLOOKUP(I3,B4:B13,XLOOKUP(I4,C3:F3,C4:F13))`

In the above formula, the second/inner XLOOKUP function will search for the value ‘Computer’ in the cells containing name of Exams (C3:F3) and will return the array of Marks in the corresponding column (57, 53, 68, 89, 98, 50, 72, 74, 87, 86). This array will become the third argument of the first/outer XLOOKUP function.

```=XLOOKUP(I4,C3:F3,C4:F13)

={57;53;68;89;98;50;72;74;87;86}```

The first/outer XLOOKUP function will search for ‘Hana’ in the cells containing name of the Candidates (B4:B13) and when found will return the corresponding mark from the array generated using the second/inner XLOOKUP function.

```=XLOOKUP(I3,B4:B13,XLOOKUP(I4,C3:F3,C4:F13))

=72```

### 2 Way Lookup using VLOOKUP

The VLOOKUP function is designed to search for the Lookup value in the first column of a table and return the corresponding value from the specified column of that table. Normally this column number will be hard coded inside VLOOKUP function. But, using the MATCH function we can make this column number dynamic and force the VLOOKUP function to perform a 2 Way Lookup.

The following formula will return the marks scored by Hana for her Computer exam.

`=VLOOKUP(I3,B4:F13,MATCH(I4,B3:F3,0),FALSE)`

In the above formula, MATCH function will search for the value ‘Computer’ in the cells from B3:F3 and will return the value 4.

```=MATCH(I4,B3:F3,0)

=4```

The value 4, returned by MATCH function will become the 3rd argument of VLOOKUP function and will return the score from 4th column of the table.

```=VLOOKUP(I3,B4:F13,MATCH(I4,B3:F3,0),FALSE)

=72```

### 2 Way Lookup using INDEX and MATCH functions

The INDEX function in Excel can be used extract the value present in the specified location of a Table or an Array. The location is defined using the Row and Column number.

The formula =INDEX(Data, 2, 5) will return the value present in the 2nd row of the 5th column of the table called Data.

To find the row and column numbers corresponding to the lookup values, we will use the MATCH function.

To get the Row number corresponding to the Candidate ‘Hana’,

```=MATCH(I3,B4:B13,0)

=7```

To get the Column number corresponding to the Exam ‘Computer’,

```=MATCH(I4,C3:F3,0)

=3```

C4:F13 is the data range containing Marks.

Combining all these, the formula will become

```=INDEX(C4:F13,MATCH(I3,B4:B13,0),MATCH(I4,C3:F3,0))

=72```