Ch-3 Lookup Functions
Ch-3 Lookup Functions
Lookup functions
Way to study:
Step 1: Read the problems of the chapter with input data.
Step 2: Find out the domain area of each problem.
Step 3: If it’s a new area, learn at first main business domain knowledge and KPIs of that area
from other sources like GPT and from this book.
Step 4: Find out and learn and note any new knowledge of MS-Excel required (from this book or
any other sources like Bakaly’s videos) here or in its Excel (core) folder.
Step 5: Output / solution of the problem.
Step 6: The same goes for the Exercise questions except that you need to do step 4 completely
by your own.
VLOOKUP:
Definition:
It’s a searching function for a specific value of a column in a range of cells/table corresponding to
a “specific value” of another column in the same range of cells/table. And we use lookup
function (means typing the VLOOKUP formula) outside the range of cells where we have to
search. And that “specific value” in another cell of that outside area is also mentioned as first
argument of VLOOKUP function.
That outside area can be in the same sheet or another sheet.
And that cell (where we are typing VLOOKUP function) can be extended using relative/partial
referencing to entire column.
Example:
o Suppose we have this range of cells/table in sheet “Item List”. Concentrate what data is given:
o And we have another sheet “VLOOKUP(Exact)-2”.
o Now here, in VLOOKUP(Exact)-2 sheet, for a specific item no. given in column “Item No.”, we
want to fill the matching Description in the column “Description”. So, for this purpose, we will
have to refer the sheet “Item List”, in which description is given for all Item Nos.
o Therefore, we will search in the related range of cells of sheet “Item No.”, the required data
(Description) for sheet “VLOOKUP(Exaxt)-2” corresponding a specific value (Item No.) given in
same “VLOOKUP(Exaxt)-2” sheet“.
o But there is a limitation! Note that we have to select the range of cells of the sheet
where we are searching (i.e. Item List) in such a way that the first column must be the
given value (i.e. Item No.).
o VLOOKUP stands for "Vertical Lookup." It's called vertical because it searches for a value in the
first column of a table array and retrieves a corresponding value in the same row from another
column. The search is vertical along a column.
If you use VLOOKUP to find the price of a Banana, it looks vertically in the "Fruit" column, finds
"Banana," and returns the corresponding value from the "Price" column, which is $0.75.
Syntax:
The syntax of the VLOOKUP function is as follows. The brackets ([ ]) indicate optional arguments:
o “Lookup value” is the value that you want to look up in the first column of the range of cells /
table range.
In our example, it is the C5 of sheet “VLOOKUP(Exaxt)-2”
o “Table range” is the range that contains the entire lookup table. The table range includes the
first column, in which you try to match the lookup value, and any other columns in which you
want to look up formula results.
Note here, we used the word “columns” because sometimes the column from which the
value is to be obtained isn’t adjacent to the lookup column. For instance, if we were searching
for Unit price then it is not the adjacent column of Item No. column and another reason you
can observe in example 2 that will be given later on.
In our example, it is B3:C12 of the sheet “Item List”. Note we have not selected the column
headings of this table range. Also note that column B is the 1st column, which is a must
requirement.
o “Column index” (starting from number 1) is the column number in the table range from which
the value of the lookup function is obtained.
In our example it is 2 (column C) of sheet “Item List”.
o Range lookup is an optional argument. The point of range lookup is to allow you to specify an
“Exact or approximate” match. If the range lookup argument is True or “omitted”, the first
column of the table range must be in “ascending” numerical order. It means the default
Range lookup argument is true. Mostly you want exact match but in some cases where there
is less than or greater than situation, approximate option is used. See further example later
on.
Now there are following rules in this regard:
If the range lookup argument is True or omitted and an exact match for the lookup value is
found in the first column of the table range, Excel bases the lookup on the row of the table
in which the exact match is found.
If the range lookup argument is True or omitted and an exact match does not exist, Excel
bases the lookup on the largest value in the first column that is less than the lookup value.
If the range lookup argument is False and an exact match for the lookup value is found in
the first column of the table range, Excel bases the lookup on the row of the table in which
the exact match is found.
If no exact match is obtained, Excel returns an #N/A (Not Available) response.
In our example, we are using FALSE to make it exact match.
So, in our example, complete formula is:
=vlookup(C5,’Item List’!B3:C12,2,FALSE)
Same formula can be dragged for other cells in the same column.
Similarly, if we are searching for Unit Price the formula would be:
=vlookup(C5,’Item List’!B3:D12,3,FALSE)
Further Examples:
VLOOKUP with string data using approximate match:
VLOOKUP with approximate match is typically used with numerical data where you're
looking for a value within a range. However, with string data, you can still find
approximate matches in certain scenarios. One common application is when you have
sorted string data and want to find the closest match.
Example 1:
Suppose you have a table with student names in the first column (A), subjects in the first row (B
to D), and corresponding grades at the intersection of each student and subject. Your table might
look like this:
| A | B | C | D |
| John | A | B | A |
| Mary | B | A | C |
| Bob | C | B | A |
Now, let's say you want to find Mary's grade in English. You can use the VLOOKUP
function for this two-dimensional search:
=VLOOKUP("Mary", A2:D4, MATCH("English", B1:D1, 0) + 1, FALSE)
Breaking it down:
MATCH("English", B1:D1, 0) + 1 finds the column index for "English" and adds 1 to get
the correct column in the table. We need to add 1 because the index returned by the
MATCH function represents the relative position of an item in a range i.e. it will not
count Student Name column. Also note that 0 is an optional argument which is called as
[match_type] that specifies the type of match: 1 for less than, 0 for an exact match, and
-1 for greater than.
[match_type]: An optional argument that specifies the type of match: 1 for less
than, 0 for an exact match, and -1 for greater than.
The MATCH function returns the relative position of the lookup_value within the
lookup_array. The first item in the range is considered to be in the 1st position.
This formula will return Mary's grade in English, which is "A" in this case. The MATCH function is
used to dynamically determine the column index based on the subject you're looking for.
Example 2:
In Chapter 12, “IF, IFERROR, IFS, CHOOSE, and SWITCH functions,” you will learn how to use the
IFERROR function to eliminate #N/A responses. Note that a range lookup argument of 1 is
equivalent to True, whereas a range lookup argument of 0 is equivalent to False.
HLOOKUP:
Definition:
The HLOOKUP function in Excel is used to look up a value in the first row of a table or range and
return a corresponding value from another row.
Example:
Let's consider a simple example where you have a table with product names in the first row
(B1:E1) and corresponding prices in the second row (B2:E2):
| | A | B | C | D | E |
Now, suppose you want to find the price of an orange. You can use HLOOKUP:
Breaking it down:
2 is the row index number, indicating we want to retrieve the value from the second row of
the table (where the prices are).
This formula will return the price of an orange, which is 1.20 in this case.
Syntax:
row_index_num: The row number in the table from which to retrieve the value.
You can use HLOOKUP with both sorted and unsorted data. The function searches for the specified value
in the first row of the table array and returns the corresponding value from the specified row.
Further Example:
WM # 13: VLOOKUP with data levels / grouped data:
Step 1: Problem with input data:
How do I write a formula to compute tax rates based on income?
Suppose that the tax rate depends on income, as shown in the following table:
$10,000–$29,999 30%
$30,000–$99,999 34%
To see an example of how to write a formula that computes the tax rate for any income level, open the
file Lookup.xlsx, shown in above data Figure.
I began by entering the relevant information (tax rates and break points(Tax rates)) in cell range D6:E9. I
named the table range D6:E9 lookup. I recommend that you always name the cells you’re using as the
table range. If you do so, you need not remember the exact location of the table range, and when you
copy any formula involving a lookup function, the lookup range will always be correct.
To illustrate how the lookup function works, I entered some incomes in the range D13:D17. By copying
from E13:E17 the formula VLOOKUP(D13,Lookup,2,True),
I computed the tax rate for the income levels listed in D13:D17.
Note in D13, the income of –$1,000 yields #N/A because –$1,000 is less than the lowest income level in
the first column of the table range. If you want a tax rate of 15 percent associated with an income of –
$1,000, simply replace the 0 in D6 by a number that is –1,000 or smaller.
In F13:F17, I changed the value of the range lookup argument from True to False and copied from F13 to
F14:F17 the formula VLOOKUP(D13,Lookup,2,False). Cell F14 still yields a 34 percent tax rate because the
first column of the table range contains an exact match to $30,000. All the other entries in F13:F17
display #N/A because none of the other incomes in D13:D17 have an exact match in the first column of
the table range. In Chapter 12, you will learn how to ensure that Excel does not return the #N/A error in
these situations.
Syntax of the INDEX function The INDEX function allows you to return the entry in any row and
column within an array of numbers. The most commonly used syntax for the INDEX function is the
following: INDEX(Array,Row Number,Column Number) To illustrate, the formula INDEX(A1:D12,2,3)
returns the entry in the second row and third column of the array A1:D12. This entry is the one in
cell C2.
1. WM # 6: Range names
Step 1: Problem with input data:
Step 2: Domain:
Step 3: Related domain knowledge / KPIs:
Step 4: Excel Knowledge required / gained:
How can I create named ranges?
Step 5: Output / solution of the problem:
2. WM # 6: Range names
Step 1: Problem with input data:
Step 2: Domain:
Step 3: Related domain knowledge / KPIs:
Step 4: Excel Knowledge required / gained:
How can I create named ranges?
Step 5: Output / solution of the problem:
3. WM # 6: Range names
Step 1: Problem with input data:
Step 2: Domain:
Step 3: Related domain knowledge / KPIs:
Step 4: Excel Knowledge required / gained:
How can I create named ranges?
Step 5: Output / solution of the problem:
4. WM # 6: Range names
Step 1: Problem with input data:
Step 2: Domain:
Step 3: Related domain knowledge / KPIs:
Step 4: Excel Knowledge required / gained:
How can I create named ranges?
Step 5: Output / solution of the problem: