unit_16_lookup and reference function

Upload: snafde69236574

Post on 14-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Unit_16_lookup and Reference Function

    1/8

    2013 Excel with Business 1 Unit 16: Lookup & Reference Functions

    Unit 16: Lookup & Reference Functions

    16.0 IntroductionOne of the most important features of Excel is its ability to look for a specific value within alarge number of cells containing data, and return a value from that row (or column). Theeasiest way to do that is to use the VLOOKUP and HLOOKUP functions. If you do a lot of analysis of large databases it will probably be worth you learning the slightly morecomplicated and much more powerful INDEX-MATCH combination of functions.

    16.1 VLOOKUP

    The VLOOKUP function looks for a specified value in the left-most column of a table of dataand returns a value from that row in one of the columns to the right.

    Consider the following data about the launch date of some popular websites:

    Assume the list goes on for thousands of lines. Suppose you are only interested in the foursocial networking sites. You could create a small list with just the sites you are interested in(column D) and then use VLOOKUP to look them up in the large table and return the

    corresponding launch dates. Type into cell E2:

  • 7/27/2019 Unit_16_lookup and Reference Function

    2/8

    2013 Excel with Business 2 Unit 16: Lookup & Reference Functions

    =VLOOKUP(D2,A:B,2,FALSE)

    to give:

    Where:

    D2 is the value were looking up. Note that writing Facebook. com for this argumentwould have achieved the same result, but we would not have been able to copy theformula down to other rows without changing it

    A:B is the range of the data we re looking in. Note, the absence of numbers in thisreference means the whole column is searched. Although this does allow for additionalentries in the columns this should be used with care. Excel 2007 and 2010 worksheetshave over 1,000,000 rows. Referring to many whole columns can slow down yourcalculations.

    2 is the column number of the value we want returned. So in this case, the column wereinterested in (Launch year) is the second one so we put 2

    FALSE indicates that we are looking for an exact match. Leaving this blank or writingTRUE would ask Excel to look for an approximate match . Note that this doesnt meanExcel will just find the closest match, Excel will find the largest value that is equal to orsmaller than the value were looking for. For an approximate match to work, the firstcolumn of our table of data must be sorted in ascending order.

    In this example, we have a small table of prices for a product showing the date from whicheach price became operative. If we wanted to find out which price to use for an invoice on acertain date, we couldnt use the exact form of VLOOKUP() because the table includes only 4dates out of the hundreds we might need to use. We have set up the data with the firstcolumn sorted in ascending order and we can see the effect of using an exact VLOOKUP()

  • 7/27/2019 Unit_16_lookup and Reference Function

    3/8

  • 7/27/2019 Unit_16_lookup and Reference Function

    4/8

    2013 Excel with Business 4 Unit 16: Lookup & Reference Functions

    Since most databases display data down columns rather than across rows, VLOOKUP is themore useful of the two.

    The limitations of VLOOKUP apply to HLOOKUP too.

    16.3 MATCH

    The MATCH function is really a lookup function which doesnt bring back any data . It justtells you if it found the value you asked it to look for and if so, where it was found. There arethree arguments in a MATCH function: what youre looking for, where youre looking for itand the kind of match you are trying to make. Using our popular websites example, supposewe think of a couple more social networking sites (Bebo and Friendster) and we want to seeif they appear in our big database. Type into cell E2:

    =MATCH(D2,A:A,0)

    And you would see something like:

    Where:

    D2 is what were looking for (in row 2 this is Facebook.com)

  • 7/27/2019 Unit_16_lookup and Reference Function

    5/8

    2013 Excel with Business 5 Unit 16: Lookup & Reference Functions

    A:A is the column were looking in 0 means that were looking for an exact match (just as with VLOOKUP and HLOOKUP its

    a good idea to use the exact match form when you are expecting an exact match; if youuse the approximate match forms then the data must be sorted accordingly)

    The resulting table is:

    The 4 in cell E2 shows the position at which Facebook.com appears in column A ( its the4 th item in the range we select). Note that, in this case, this includes the header. If wedwanted that removed we would have typed =A2:A1048576 instead of A:A. Similarly for 6,

    13, 26. The #N/As in cells E6 and E7 indicate that neither Bebo.com norFriendster.com is in the big list.

    16.4 INDEX-MATCH

    The INDEX-MATCH combination is not easy but well worth taking the time to learn,particularly if you frequently work with a lot of data. INDEX-MATCH has advantages overVLOOKUPs:

    It can be used on data arranged in columns or rows You can find a column based on matching the heading rather than having to choose a

    particular number column

    INDEX

    The INDEX function is fairly simple and can also be used on its own. It has two arguments:the list you want Excel to look at and the number in that list that you want returned. So if you wanted to have the 14 th website in the list below returned, you would write:

    =INDEX(A2:A40,14)

  • 7/27/2019 Unit_16_lookup and Reference Function

    6/8

    2013 Excel with Business 6 Unit 16: Lookup & Reference Functions

    And ESPN.go.com will be returned.

    Suppose that you have another database of website information on user ratings overvarious geographies, ordered alphabetically:

    You want to consolidate the two databases into one master database with all of thisinformation. First you need to decide if you want to add the ratings information to thelaunch spreadsheet or vice versa. This might depend on which order and format takesprecedence. Lets say were adding ratings data to launch data.

  • 7/27/2019 Unit_16_lookup and Reference Function

    7/8

    2013 Excel with Business 7 Unit 16: Lookup & Reference Functions

    Then in that database we type:

    =INDEX(Ratings!B:B,MATCH(Launch!A2,Ratings!A:A,0)

    Where:

    the yellow part of the formula indicates where we have asked Excel to look (column B of the ratings sheet)

    the green part returns the position in the ratings column A (where the sites are listedalphabetically) that Google.com shows up . Lets say this is the 100 th place down

    The INDEX therefore knows to return the 100 th Rating in column B of the Ratings sheet

    Now, to get ALL the data from the ratings sheet we want to copy a version of the formuladown, and to the right. Since we are always going to want to use match from the A columnof the Launch sheet (but not always the same row) to the A column of the Ratings sheet, wecan fix some cell references (see Unit 11: Cell References) to:

    =INDEX(Ratings!B:B,MATCH(Launch!$A2,Ratings!$A:$A,0))

    Then extending the formula down and right gives:

  • 7/27/2019 Unit_16_lookup and Reference Function

    8/8

    2013 Excel with Business 8 Unit 16: Lookup & Reference Functions

    Beware

    Like any other Excel formula and function it is easy to enter incorrectly (and harder to spotthe error than for some). You must therefore take care:

    To carry out spot checks. In the example above you might choose a cell randomly, letssay F15 to check that Go.com was rated 9.8 in the Ratings sheet.

    Sorting data. Make sure you create INDEX-MATCH functions in such a way that they stillreturn the correct result if the sort order of the data is changed.

    To keep precise data. While we advocate the use of the exact match type, this does

    require that the data you are looking amongst correspond exactly to the value you arelooking up. Sometimes you are a simple operation away from achieving this. Forexample, if the websites in the Ratings sheet all had www. in front of them, we mighthave to add these to the corresponding entries in the Launch sheet (with &) or byremoving them from the Ratings sheet (using Find & Replace or LEFT & LEN).