# Join tables with INDEX and MATCH

To join or merge tables that have a common id, you can use the INDEX and MATCH functions. In the example shown, the formula in E5 is:

where "data" is the named range H5:J8 and "ids" is the named range H5:H8.

This formula pulls the customer name and state from the customer table into the order table. The MATCH function is used to locate the right customer and the INDEX function is used to retrieve the data.

### Retrieving customer name

Working from the inside out, the MATCH function is used to get a row number like this:

MATCH($C5,ids,0)

- The lookup value comes the customer id in C5, which is a mixed reference, with the column locked, so the formula can be easily copied.
- The lookup array is the named range ids (H5:H8), the first column in the customer table.
- The match type is set to zero to force an exact match.

The MATCH function returns 2 in this case, which goes into INDEX as the row number:

=INDEX(data,2,2)

With the column number hard-coded as 2 (customer names are in column 2) and the array set to the named range "data" (H5:J8) INDEX returns: Amy Chang.

### Retrieving customer state

The formula to retrieve customer state is almost identical. The only difference is the column number is hard-coded as 3, since state info appears in the 3rd column:

### Dynamic two-way match

By adding another MATCH function to the formula, you can set up a dynamic two-way match. For example, with the named range "headers" for H4:J4, you can use a formula like this:

Here, a second MATCH function has been added to get the correct column number. MATCH uses the current column header in the first table to locate the correct column number in the second table, and automatically returns this number to INDEX.

## Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

## Download 100+ Important Excel Functions

Get over 100 Excel Functions you should know in one handy PDF.