Thursday, 8 December 2016

Lookup & Reference Functions

Learn all about Excel's lookup & reference functions such as the VLOOKUP, HLOOKUP, MATCH, INDEX and CHOOSE function.
VLookup
The VLOOKUP (Vertical lookup) function looks for a value in the leftmost column of a table, and then returns a value in the same row from another column you specify.
1. Insert the VLOOKUP function shown below.
VLookup Function in Excel
Explanation: the VLOOKUP function looks for the ID (104) in the leftmost column of the range $E$4:$G$7 and returns the value in the same row from the third column (third argument is set to 3). The fourth argument is set to FALSE to return an exact match or a #N/A error if not found.
2. Drag the VLOOKUP function in cell B2 down to cell B11.
Copy Vlookup Function
Note: when we drag the VLOOKUP function down, the absolute reference ($E$4:$G$7) stays the same, while the relative reference (A2) changes to A3, A4, A5, etc.
HLookup
In a similar way, you can use the HLOOKUP (Horizontal lookup) function.
HLookup Function
Match
The MATCH function returns the position of a value in a given range.
Match Function
Note: Yellow found at position 3 in the range E4:E7. The third argument is optional. Set this argument to 0 to return the position of the value that is exactly equal to lookup_value (A2) or a #N/A error if not found.
Index
The INDEX function returns a specific value in a two-dimensional or one-dimensional range.
Index Function, Two-dimensional Range
Note: 92 found at the intersection of row 3 and column 2 in the range E4:F7.
Index Function, One-dimensional Range
Note: 97 found at position 3 in the range E4:E7.
Choose
The CHOOSE function returns a value from a list of values, based on a position number.
Choose Function
Tax Rates

Sometimes you are not looking for an exact match when you use the VLOOKUP function in Excel. For example, when you want to calculate the tax on an income.
The following tax rates apply to individuals who are residents of Australia.
Taxable income
Tax on this income
0 - $6,000
Nil
$6,001 - $35,000
15c for each $1 over $6,000
$35,001 - $80,000
$4,350 plus 30c for each $1 over $35,000
$80,001 - $180,000
$17,850 plus 38c for each $1 over $80,000
$180,001 and over
$55,850 plus 45c for each $1 over $180,000

Example: if income is 37000, tax equals 4350 + 0.3 * (37000 - 35000) = 4350 + 600 = $4950
Tax Rates in Excel
To automatically calculate the tax on an income, execute the following steps.
1. On the second sheet, create the following range and name it Rates.
Named Range
2. We already know how the VLOOKUP function can return an exact match or a #N/A error if not found, by setting the fourth argument to FALSE. However, when you set this argument to TRUE, it returns an exact match or if not found, it returns the largest value smaller than lookup_value (A2). That's exactly what we want!
VLookup Function
Explanation: Excel cannot find 37000 in the first column of Rates. However, it can find 35000 (the largest value smaller than 37000). As a result, it returns 4350 (col_index_num, the third argument, is set to 2).
3. Now, what's left is the remainder of the equation, + 0.3 * (37000 - 35000). This is easy. We can return 0.3 by setting col_index_num to 3 and return 35000 by setting col_index_num to 1. The complete formula below does the trick.
Tax Rates Formula
Note: when you set the fourth argument of the VLOOKUP function to TRUE, the first column of the table must be sorted in ascending order.
Offset

The OFFSET function in Excel returns a cell or range of cells that is a specified number of rows and columns from a cell or range of cells.
1. The OFFSET function below returns the cell that is 3 rows below and 2 columns to the right of cell A2. The OFFSET function returns a cell because the height and width are both set to 1.
Offset Cell Example
Result:
Offset Cell Result
2. The OFFSET function below returns the 1 x 2 range that is 5 rows below and 1 column to the right of cell A2. The SUM function calculates the sum of this range.
Offset Range Example
Result:
Offset Range Result
Note: to return a range (without calculating the sum), select a range of the same size before you insert the OFFSET function. If you want to return a cell or range of cells that is a specified number of rows above or columns to the left, enter a negative number.
Left Lookup

A drawback of the VLOOKUP function is that it can only look up values in the leftmost column of a table. However, sometimes you need to look up a value in any column and return the corresponding value to the left. To achieve this, simply use the INDEX and the MATCH function.
1. The MATCH function returns the position of a value in a given range.
Match Function in Excel
Explanation: 104 found at position 4 in the range $G$4:$G$7.
2. Use this result and the INDEX function to return the 4th value in the range $E$4:$E$7.
Index Function in Excel
3. Drag the formula in cell B2 down to cell B11.
Drag the Formula Down
Note: when we drag this formula down, the absolute references ($E$4:$E$7 and $G$4:$G$7) stay the same, while the relative reference (A2) changes to A3, A4, A5, etc.
Two-way Lookup

This example teaches you how to lookup a value in a two-dimensional range. We use the MATCH and INDEX function.
Below you can find the sales of different ice cream flavors in each month.
1. To find the row number of Feb, use the MATCH function.
Match Function
2. To find the column number of Chocolate, use the MATCH function.
Match Function
3. To find the sales of Chocolate in February, use the INDEX function.
Index Function
4. Put it all together.
Two-way Lookup Result
Locate Maximum Value

This example teaches you how to find the cell address of the maximum value in a column.
1. First, we use the MAX function to find the maximum value in column A.
Max Function in Excel
2. Second, we use the MATCH function to find the row number of the maximum value.
Match Function in Excel
Explanation: the MATCH function reduces to =MATCH(12,A:A,0), 7. The MATCH function returns the position of the maximum value in column A. Set the third argument to 0 to return an exact match.
3. Finally, we use the ADDRESS function to return the cell address.
Address Function in Excel
Explanation: the ADDRESS function reduces to =ADDRESS(7,1), $A$7. The first argument specifies the row number. The second argument specifies the column number.
Indirect

The INDIRECT function in Excel returns the reference specified by a text string.
1. For example, the INDIRECT function below reduces to =INDIRECT("C2"), =C2, 5
Cell
Do we really need the INDIRECT function for this? Yes. Below you can find the result without using the INDIRECT function.
Without Indirect Function
2. For example, the function below reduces to =SUM(INDIRECT("E3:E6")), =SUM(E3:E6), 27
Range
Note: the & operator is used to join strings. Border for illustration only.
3. For example, the function below reduces to =AVERAGE(Scores), 9
Name
Note: the named range Scores refers to the range C2:C4.


No comments:

Post a Comment