Microsoft Excel Lookup Functions

Transcription

Microsoft Excel Lookup Functions
Microsoft Excel Lookup Functions - Reference Guide
LOOKUP Functions - Description
Excel Lookup functions are used to look up and extract data from a list or table and insert the data into
another list or table. Use the appropriate lookup function depending on how your data is organized.
The following functions are explained below:
• VLOOKUP
• HLOOKUP
• Fuzzy Lookup
VLOOKUP
Excel VLOOKUP is a useful function to compare data in two spreadsheets when the lookup values are
contained in the first column of a lookup table. It can be used to import data from one spreadsheet to
another for comparison purposes. Once you have become familiar with VLOOKUP, you will find it a
valuable tool to use for data analysis.
Syntax
VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
•
•
•
•
lookup_value: the value you want to search, or look up, in the first column of a table or range.
Required argument.
table_array: the range of cells where you want to look up the comparison data. The values in
the first column of the table_array are the values searched by the lookup_value. These can be
text, numbers or logical values and are not case sensitive. Required argument.
col_index_num: The number of the column in the table_array from which the matching value
must be returned. For example, a col_index_num argument of 1 returns the value in the first
column in table_array, a col_index_num argument of 2 returns the value in the second column
in table_array, etc. Required argument.
range_lookup: A logical value specifying whether you want VLOOKUP to find an exact match
or an approximate match. If omitted, defaults to TRUE (1) for an approximate match, so if an
exact match is not found, the next highest value in a range will be returned. Recommend that
FALSE (0) be used in most cases. Optional argument.
Helpful Hints:
• When searching text values, make sure the data in the first column of table_array does not
contain any trailing or leading spaces, inconsistent use of straight and curly quotation marks, or
nonprinting characters. Otherwise, VLOOKUP could return an incorrect or unexpected value.
• When searching number or date values, make sure data in the first column of table_array is not
stored as text values. Otherwise, VLOOKUP could return an incorrect or unexpected value.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
1 of 13
Microsoft Excel Lookup Functions - Reference Guide
•
If the lookup_value is not found in the first column of the table_array, then the “#N/A” error
value is returned.
Step-by-Step Example
The following example uses the data from Exercise 1 demonstrated in the FAST Excel Lookups class,
which has two worksheets, Trial_Balance and Account_Listing. The values in the Account Description
column in the Account_Listing worksheet will be used to populate the blank column in the Trial_Balance
worksheet, based on the value in Account.
1) Be sure the data you are using to match is in the left column of each worksheet. In this example
you will only use columns C (account) and D (blank column for inserting account description) in
Trial_Balance and columns C (Account) and D (Account Description) Account_Listing for the
VLOOKUP.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
2 of 13
Microsoft Excel Lookup Functions - Reference Guide
2) Navigate to the Trial_Balance worksheet and place the cursor in the blank cell to the right of
Account 10010, where the first VLOOKUP formula will be placed. Click on ‘fx’ in the formula
bar. The Insert Function window will display. Type VLOOKUP in the Search for a function
field and click Go. Select VLOOKUP from the search list then click on OK.
3) A dialog box will display where you can enter the lookup ranges and values. In the
Lookup_value field navigate to cell C17, where the value is ‘10010’ to populate the Lookup_value
field.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
3 of 13
Microsoft Excel Lookup Functions - Reference Guide
4) Click on the Table_array field in the Function Arguments window then navigate to the
Account_Listing worksheet. Highlight columns C and D. (Note: If Table_array does not include
an entire set of columns, then use absolute cell references. For example, if Table_array is only
the range defined by C10 through D15, then the Table_array value would be $C$10:$D$15.
5) Enter ‘2’ in the Col_index_num field. This indicates the value in the second column of the
Table_array will be used to populate Account Description in Trial_Balance. Type ‘false’ or ‘0’ in
Range_lookup to indicate an exact match should be found for Account.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
4 of 13
Microsoft Excel Lookup Functions - Reference Guide
6) Click on OK. The Account Description in Trial_Balance should be populated with the title for
Account 10010.
7) Copy the formula in cell C17 to the remaining rows in the column. Account Description values
will be populated based on Account. If a match is not found, then the error code, ‘#N/A’, will
display.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
5 of 13
Microsoft Excel Lookup Functions - Reference Guide
HLOOKUP
Use HLOOKUP, or horizontal lookup, when the lookup values are contained in the first row of a table,
and the values to be returned are in the same column but in a different row that you specify.
Syntax
HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])
•
•
•
•
lookup_value: the value to search in the first row of a table or range. Required argument.
table_array: the range of cells where you want to look up the comparison data. The values in
the first row of the table_array are the values searched by lookup_value. These can be text,
numbers, or logical values and are not case sensitive. Required argument.
row_index_num: The row number in the table_array from which the matching value must be
returned. For a example, a row_index_num argument of 1 returns the value in the first row in
table_array, a row_index_num argument of 2 returns the value in the second row in
table_array, etc. Required argument.
range_lookup: A logical value specifying whether you want HLOOKUP to find an exact match
or an approximate match. If omitted, defaults to TRUE (1) for an approximate match.
Recommend that FALSE (0) be used in most cases. Optional argument.
Helpful Hints:
• When searching text values, make sure the data in the first row of table_array does not contain
any trailing or leading spaces, inconsistent use of straight and curly quotation marks, or
nonprinting characters. Otherwise, HLOOKUP could return an incorrect or unexpected value.
• When searching number or date values, make sure data in the first row of table_array is not
stored as text values. Otherwise, HLOOKUP could return an incorrect or unexpected value.
• If the lookup_value is not found in the first row of the table_array, then the “#N/A” error value
is returned.
Step-by-Step Example
The following example uses the data from Exercise 3 demonstrated in the FAST Excel Lookups class,
which has three worksheets, AR_Transactions, Detail_Codes, and Account_Listing. HLOOKUP will be
used to populate Account in AR_Transactions from Detail Code Acct B in Detail_Codes, based on Detail
Code.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
6 of 13
Microsoft Excel Lookup Functions - Reference Guide
1) Navigate to cell B4 in AR_Transactions. Open up the formula wizard by clicking on the
Formulas tab, then Lookup & Reference, and selecting HLOOKUP.
2) The Function Arguments dialog window will display. In the Lookup_value field, click in cell A4,
to populate the field contents.
3) For Table_array, navigate to Detail_Codes and highlight rows 2 through 21. Insert a ‘$’ before
each row number to make the table reference absolute. If the table reference is not made
absolute, then the HLOOKUP formula cannot be easily copied to remaining rows.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
7 of 13
Microsoft Excel Lookup Functions - Reference Guide
4) Enter ‘17’ in the Row_index_num field. This indicates the value in row 17 of the Table_array
defined by rows 2 through 21 in Detail_Codes will be used to populate Account in
AR_Transactions. Type ‘false’ or ‘0’ in Range_lookup to indicate an exact match should be found
by Detail Code.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
8 of 13
Microsoft Excel Lookup Functions - Reference Guide
5) Click on OK. The Account for Detail Code OPRD in AR_Transactions should be populated with
‘11010’, which is the Detail Code Acct B associated with OPRD from the Detail_Codes worksheet.
6) Copy the formula in cell B4 to the remaining rows in the column. Account Description will be
populated based on Detail Code. If a match is not found, then the error code, ‘#N/A’, will display.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
9 of 13
Microsoft Excel Lookup Functions - Reference Guide
Fuzzy Lookup
Fuzzy Lookup is an Excel Add-In tool developed by Microsoft to be used for comparing textual data that
is not an exact match, also referred to as “fuzzy matching”. Before you can use this feature, follow the
Installing the Fuzzy Lookup Excel Add-In instructions to download the tool.
The following example uses the tables from Exercise 4 demonstrated in the FAST Excel Lookups class,
which has two worksheets, Phone_List and Email_List.
1) Fuzzy Lookup needs data set up in tables to compare values. For each worksheet, click on any cell
containing a value. Select the Table command from the Insert tab. Alternatively, highlight the entire
table and press CTRL + L. The Create Table window will display. Check the “My table has
headers” box, then click on OK.
2) Once the tables are created, click on the Fuzzy Lookup tab
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
10 of 13
Microsoft Excel Lookup Functions - Reference Guide
3) Then click on the Fuzzy Lookup icon in the upper left corner.
4) The Fuzzy Lookup menu will appear on the right.
•
•
•
At the top of the menu, the two tables to be compared should be shown. If these fields are blank,
click on the drop-down arrow and select the appropriate table names.
The highlighted fields in Left Columns and Right Columns indicate how the tables are compared.
In the Match Columns section, the two columns to be compared should be pre-selected. Change
the column selection if needed.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
11 of 13
Microsoft Excel Lookup Functions - Reference Guide
•
•
•
In the Output Columns section, the columns to be displayed in the output are checked. The
FuzzyLookup.Similarity column indicates we want to display the system-generated Similarity
score.
The merged data set will be placed wherever the currently highlighted cell is located.
After completing your selections above, click on Go in the lower right corner.
5) The Fuzzy Lookup tool analyzes the data and displays the results. Note that matches based on Name
were found for all but one of the rows. The Fuzzy Lookup adds a column called ‘Similarity’ which
shows how confident the tool is in its comparison of the data sets. A score of 1.0 indicates a perfect
match. The closer to 1.0, the closer the match the tool was able to make.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
12 of 13
Microsoft Excel Lookup Functions - Reference Guide
6) The Similarity Threshold can be changed to try and increase the number of matches, but which also
decreases the confidence level. The threshold was decreased to .25, illustrated below.
7) In the second list below are the results with a Similarity Threshold of .25. Notice that a match has
now been found for Jane Chapman.
Finance Systems | Excel Lookup Functions | Reference Guide
March 2013
13 of 13