You are on page 1of 8

CHAPTER 4

MATCH function

Questions answered in this chapter:


■■ Given monthly sales for several products, how can I write a formula that returns the sales of a
product during a specific month? For example, how much of Product 2 did I sell during June?

■■ Given a list of baseball players’ salaries, how can I write a formula that yields the player with
the highest salary? How about the player with the fifth-highest salary?

■■ Given the annual cash flows from an investment project, how do I write a formula that returns
the number of years required to pay back the project’s initial investment cost?

Suppose you have a worksheet with 5,000 rows containing 5,000 names. You need to find the name
John Doe, which you know appears somewhere (and only once) in the list. Wouldn’t you like to
know of a formula that would return the row number that contains that name? The MATCH function
enables you to find the first occurrence of a match to a given text string or number within a given
array. You should use the MATCH function instead of a lookup function when you want the position
of a number in a range rather than the value in a particular cell. The syntax of the match function is:

Match(lookup value,lookup range,[match type])

In the explanation that follows, assume that all cells in the lookup range are in the same column. In
this syntax:

■■ Lookup value is the value you’re trying to match in the lookup range.

■■ Lookup range is the range you’re examining for a match to the lookup value. The lookup
range must be a row or column.

■■ Match type=1 requires the lookup range to consist of numbers listed in ascending order. The
MATCH function then returns the row location in the lookup range (relative to the top of the
lookup range) that contains the largest value in the range that is less than or equal to the
lookup value.

■■ Match type=–1 requires the lookup range to consist of numbers listed in descending order.
The MATCH function returns the row location in the lookup range (relative to the top of the
lookup range) that contains the last value in the range that is greater than or equal to the
lookup value.

27

■■ Match type=0 returns the row location in the lookup range that contains the first exact match
to the lookup value. (Chapter 19, “COUNTIF, COUNTIFS, COUNT, COUNTA, and COUNTBLANK
functions,” discusses how to find the second or third match.) When no exact match exists and
match type=0, Excel returns the error message #N/A. Most MATCH function applications use
match type=0, but if match type is not included, match type=1 is assumed. Thus, use match
type=0 when the cell contents of the lookup range are unsorted. This is the situation you usu-
ally face.

The Matchex.xlsx file, shown in Figure 4-1, contains three examples of the MATCH function’s
syntax.

FIGURE 4-1  Use the MATCH function to locate the position of a value in a range.

In cell B13, the MATCH(“Boston”,B4:B11,0) formula returns 1 because the first row in the B4:B11
range contains the value Boston. Text values must be enclosed in quotation marks (“”). In cell B14, the
MATCH(“Phoenix”,B4:B11,0) formula returns 7 because cell B10 (the seventh cell in B4:B11) is the first
cell in the range that matches Phoenix. In cell E12, the MATCH(0,E4:E11,1) formula returns 4 because
the last number that is less than or equal to 0 in the E4:E11 range is in cell E7 (the fourth cell in the
lookup range). In cell G12, the MATCH(–4,G4:G11,–1) formula returns 7 because the last number that
is greater than or equal to –4 in the G4:G11 range is contained in cell G10 (the seventh cell in the
lookup range).

The MATCH function can also work with an inexact match. For example, the
MATCH(“Pho*”,B4:B11,0) formula returns 7. The asterisk is treated as a wildcard, which means that
Microsoft Excel searches for the first text string in the B4:B11 range that begins with Pho. Incidentally,
this same technique can be used with a lookup function. For example, in the price lookup exercise in
Chapter 2, “Lookup functions,” the VLOOKUP(“x*”,lookup2,2) formula would return the price of prod-
uct X212 ($4.80).

If the lookup range is contained in a single row, Excel returns the relative position of the first match
in the lookup range, moving from left to right. As shown in the following examples, the MATCH func-
tion is often very useful when it is combined with other Excel functions such as VLOOKUP, INDEX,
or MAX.

28  Chapter 4  MATCH function


Answers to this chapter’s questions
This section provides the answers to the questions that are listed at the beginning of the chapter.

Given monthly sales for several products, how can I write a formula that returns the sales of a
product during a specific month? For example, how much of Product 2 did I sell during June?

The Productlookup.xlsx file (shown in Figure 4-2) lists sales of four NBA bobble-head dolls from
January through June. How can you write a formula that computes the sales of a given product dur-
ing a specific month? The trick is to use one MATCH function to find the row that contains the given
product and another MATCH function to find the column that contains the given month. You can
then use the INDEX function to return the product sales for the month.

FIGURE 4-2 The MATCH function can be used in combination with functions such as INDEX and VLOOKUP. The
range B4:G7 contains sales data for the dolls and is named Sales.

This figure shows how MATCH and INDEX functions can be combined to look up sales for any
month and player combination. The range B4:G7 contains sales data for the dolls and is named Sales.
The product you want to know about is in cell A10 and the month is in cell B10. In C10, you use the
MATCH(A10,A4:A7,0) formula to determine which row number in the Sales range contains sales fig-
ures for the Kobe doll. Then, in cell D10, use the MATCH(B10,B3:G3,0) formula to determine which col-
umn number in the Sales range contains June sales. Now that you have the row and column numbers
that contain the sales figures you want, you can use the INDEX(Sales,C10,D10) formula in cell E10 to
yield the piece of sales data that’s needed. For more information on the INDEX function, see Chapter
3, “The INDEX function.”

Given a list of baseball players’ salaries, how can I write a formula that yields the player with
the highest salary? How about the player with the fifth-highest salary?

The Baseball.xlsx file (see Figure 4-3) lists the salaries paid to 401 Major League Baseball players dur-
ing the 2001 season. The data is not sorted by salary, and you want to write a formula that returns
the name of the player with the largest salary as well as the name of the player with the fifth-highest
salary.

MATCH function  Chapter 4   29


To find the name of the player with the highest salary, proceed as follows:

1. Use the MAX function to determine the value of the highest salary.

2. Use the MATCH function to determine the row that contains the player with the highest salary.

3. Use a VLOOKUP function (keying off the data row containing the player’s salary) to look up
the player’s name.

The range C12:C412 includes players’ salaries and is named Salaries. The range used in the
VLOOKUP function (range A12:C412) is named Lookup.

FIGURE 4-3  This example uses the MAX, MATCH, and VLOOKUP functions to find and display the highest value in
a list.

In cell C9, you find the highest player salary ($22 million) with the MAX(Salaries) formula. Next,
in cell C8, you use the MATCH(C9,Salaries,0) formula to determine the player number of the player
with the highest salary. Variable match type=0 was used because the salaries are not listed in either
ascending or descending order. Player number 345 has the highest salary. Finally, in cell C6, you use
the VLOOKUP(C8,Lookup,2) function to find the player’s name in the second column of the lookup
range. Not surprisingly, Alex Rodriguez was the highest-paid player in 2001.

30  Chapter 4  MATCH function


To find the name of the player with the fifth-highest salary, you need a function that yields the
fifth-largest number in an array. The LARGE function does that job. The syntax of the LARGE func-
tion is LARGE(cell range,k). When it is entered this way, it returns the kth-largest number in a cell
range. Thus, the LARGE(salaries,5) formula in cell D9 yields the fifth-largest salary ($12.6 million).
Proceeding as before, you find that Derek Jeter is the player with the fifth-highest salary. (The dl
before Jeter’s name indicates that at the beginning of the season, Jeter was on the disabled list.) The
SMALL(salaries,5) function would return the fifth-lowest salary.

Given the annual cash flows from an investment project, how can I write a formula that
returns the number of years required to pay back the project’s initial investment cost?

The Payback.xlsx file, shown in Figure 4-4, shows the projected cash flows for an investment project
over the next 15 years. Assume that in Year 1, the project required a cash outflow of $100 million.
During Year 1, the project generated a cash inflow of $14 million. You expect cash flows to grow at 10
percent per year. How many years will pass before the project pays back its investment?

The number of years required for a project to pay back an investment is called the payback period.
In high-tech industries, the payback period is often used to rank investments. (You learn in Chapter 7,
“Evaluating investments by using net present value criteria,” that payback is flawed as a measure of
investment quality because it ignores the value of money over time.) For now, concentrate on how to
determine the payback period for this simple investment model.

FIGURE 4-4  Use the MATCH function to calculate an investment’s payback period.

MATCH function  Chapter 4   31


To determine the payback period for the project, proceed as follows:

1. In column B, compute the cash flows for each year.

2. In column C, compute the cumulative cash flows for each year.

Now you can use the MATCH function (with match type=1) to determine the row number of the
first year in which cumulative cash flow is positive. This calculation gives you the payback period.

The cells in B1:B3 have the range names listed in A1:A3. Year 0 cash flow (–Initial_investment) is
entered in cell B5. Year 1 cash flow (Year_1_cf) is entered in cell B6. Copying the B6*(1+Growth) for-
mula from B7 to B8:B20 computes the cash flow for Year 2 through Year 15.

To compute the Year 0 cumulative cash flow, use the B5 formula in cell C5. For later years, you
can calculate cumulative cash flow by using a formula such as Year t cumulative cash flow=Year t–1
cumulative cash flow+Year t cash flow. To implement this relationship, copy the =C5+B6 formula from
C6 to C7:C20.

To compute the payback period, use the MATCH function (with match type=1) to compute the last
row of the C5:C20 range containing a value less than 0. This calculation always gives you the payback
period. For example, if the last row in C5:C20 that contains a value less than 0 is the sixth row in the
range, the seventh value marks the cumulative cash flow for the first year the project is paid back.
Because your first year is Year 0, the payback occurs during Year 6. Therefore, the formula in cell E2,
MATCH(0,C5:C20,1), yields the payback period (6 years). If any cash flows after Year 0 are negative, this
method fails because the range of cumulative cash flows would not be listed in ascending order.

Problems
1. Using the distances between US cities given in the Index.xlsx file, write a formula using the
MATCH function to determine (based on the names of the cities) the distance between any
two of the cities.

2. The Matchtype1.xlsx file lists the dollar amounts of 30 transactions in chronological order.
Write a formula that yields the first transaction for which total volume to date exceeds
$10,000.

3. The Matchthemax.xlsx file gives the product ID codes and unit sales for 265 products. Use the
MATCH function in a formula that yields the product ID code of the product with the largest
unit sales.

4. The Buslist.xlsx file gives the amount of time between bus arrivals (in minutes) at 45th Street
and Park Avenue in New York City. Write a formula that, for any arrival time after the first bus,
gives the amount of time you have to wait for a bus. For example, if you arrive 12.4 minutes
from now, and buses arrive 5 minutes and 21 minutes from now, you wait 21 – 12.4 = 8.6
minutes for a bus.

32  Chapter 4  MATCH function


5. The Salesdata.xlsx file contains the number of computers each salesperson sold. Create a for-
mula that returns the units a given salesperson sold.

6. Suppose the VLOOKUP function was removed from Excel. Explain how you could still get
along by using the MATCH and INDEX functions.

MATCH function  Chapter 4   33

You might also like