Showing posts with label lookup functions. Show all posts
Showing posts with label lookup functions. Show all posts

Two-way lookup in Excel 2013 using INDEX and MATCH

Two-way lookup gives value of the intersection of desired row and column values in a table containing data.

For example, suppose we have data as per table below, and we are looking for number of bank transactions of David in the month of August. This requirement is appropriate to go for 2 way lookup.

i.e. We are looking up value at intersection of desired customer name row (David) and desired month column (August)

To lookup the desired name of customer (e.g. David), we will use MATCH function. This function returns the relative position of particular value in the given cell range or an array.

Syntax for MATCH function:
MATCH (lookup_value, lookup_array, [match_type]

lookup_value: the value whose relative position is required
lookup_range: the range in which the relative position is to be found
[match_type]: put "0" for exact match

Thus, we will get relative row number of the customer by using MATCH function.

Similarly, to get relative column position of desired month we will use MATCH function.

Now, we have relative position of both row as well as column in the data table. To lookup the output value we will now use INDEX function.

Remember, the INDEX function gives ouput corresponding to given relative row number and column number in the data table.

Syntax for INDEX function:
INDEX (array, [row_num], [col_num])

array: the defined range of cells or an array to use in the lookup (basically the table with data)
[row_num]: relative row number in the defined range of cells
[col_num]: relative column number in the defined range of cells

Please note that "array" would not contain the row and column headings.

Thus, now the story is pretty clear. We need to feed the MATCH function used to fetch relative row number in place of [row_num] in INDEX function. Similarly, feed the MATCH function for relative column number in [col_num].

The final formula will look something like this:

Solutions for VLOOKUP not working or showing #N/A

Major reasons for your VLOOKUP not working properly or showing error (#N/A or #REF!) could be:
  1. The Lookup values have Trailing space at the end
  2. The Numbers entered have been formatted as Text
  3. You forgot to reference lock your table array
  4. The file or table array to lookup has been deleted
So, let's tackle these issues and get solution for each of them.
1. Lookup values having trailing space at the end
Let's look at the below VLOOKUP example. Although, the values are available in the source table, the lookup table is not returning values for some of them. The problem is not directly evident. To see the problem, go to the lookup value in the source table and click the cursor at the very end of value. The extra space will be evident at the end of the input.
Solution: It is very simple. Please remove the extra space by pressing "Backspace" in edit mode.
2. The numbers entered have been formatted as Text (shows #N/A error)
In case none of the lookup value are not returning results (#N/A is appearing), it may be possible that the formatting of source is incorrect (the numbers will appear to be aligned left).  Click on the lookup reference of the data set and check in the formula bar if there is an apostrophe before your entry.
This is sometimes intentionally done to populate leading zero in the number (although a better way is through custom formatting...!!).
Solution: Again, the solution is very simple. Multiply all your lookup values by 1. This will convert all of them into number format (the numbers will get automatically aligned right).
3. You forgot to reference lock your table array
This is very common problem that occurs when we drag the VLOOKUP formula after entering it in one cell. Often we forget to lock the table array and as a result the lookup values you are trying to match are no longer part of original lookup array (since the lookup array also shifts down when we drag it).
Solution: Before dragging the VLOOKUP formula, press F4 key to lock lookup array (in edit mode)
4. The file or table array to lookup has been deleted (shows #REF! error)
Sometimes the source data used for VLOOKUP function gets deleted or sheets are improperly moved without reference. In such case VLOOKUP shows #REF! error.
Solution: Try and locate the source data and verify the linking of VLOOKUP formula again

How to use CHOOSE function in Excel 2013

Excel's Lookup functions like VLOOKUP, HLOOKUP, CHOOSE, INDEX, MATCH etc. are used to find and return data from a list or table based on a lookup value or index number.
In CHOOSE function, it uses an index number to find and return a specific value from a corresponding list of data. The index number indicates the position of the value in the list.
Syntax:     CHOOSE(index_num, value1, [value2], [value3]....[value254])
  • index_num: Specifies the Value is to be returned by the function. It could be a number or formula or a cell reference. The value for this should be betweent 1 and 254.
  • value1: The value/data we want to fetch when "index_num" equals 1
  • value2: The value/data we want to fetch when "index_num" equals 2
The value/data for output { value1, value2, .....etc.} could be numbers, cell references, defined names, formulas, functions, or text.
IMPORTANT NOTES:
  • If index_num < 1 OR if index_num > "number of values" then Excel gives #VALUE! error
  • If index_num is a fraction, it is changed to the lowest integer before being used (eg. 3.8 to 3)
  • If index_num is an array, every value is evaluated when CHOOSE is evaluated

How to use VLOOKUP in Excel 2013

VLOOKUP is probably one of the most useful function in Excel when it comes to looking up fields related to a variable. We can use the VLOOKUP function to search the first column of a range of cells, and then return a value from any cell on the same row of the range.
The V in VLOOKUP stands for Vertical i.e. it looks up in vertical table. Since most of the real world data appears in vertical table, the VLOOKUP is one of the most used function in Excel. It works similar to human mind, first it searches for relevant key item and goes further in the row to get it's details.
Let's understand this better by most commonly encountered real world example of Employee details. Suppose a company has 10 employees with unique Employee ID followed by details like Name, Departement, Contact Number and E-mail ID.
If we need the Contact Number corresponding to Employee ID 201309 we first search the row in which this ID exists and then we move further in the same row to locate Contact Number. That's exactly how Excel also works, we just need to feed the data for what we are looking and from where we need to look.
Syntax:      VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
  • lookup_value: Insert the value to search in the first column of range or table. This value could be a value or it could be a cell reference (more dynamic). This helps excel to identify the row in which our data exists.
  • table_array: The entire range of cells that contains data. We can directly use the range reference or a range name. This tells excel the location for search.
  • col_index_num: The column in range selected under table_array corresponding to desired matching value field. (eg. Contact Number lies in column 4, hence 4 should be inserted)
  • range_lookup: Optional field. Specifies whether we need exact match or approximate match. FALSE (or 0) corresponds to exact match while TRUE (or 1) corresponds to approximate match. The default value is FALSE (or 0) i.e. exact match.
IMPORTANT NOTES:
  • If col_index_num < 1, Excel gives #VALUE! error
  • If col_index_num > number of columns in range, Excel gives #REF! error
  • While searching for text values in the first column, ensure that any cell value does not contain leading spaces, trailing spaces or inconsistent quotation marks. It may give error or incorrect values in the output.
  • While searching for number or date values in the first column, ensure that data is stored in appropriate format (not as text format)