Showing posts with label Index. Show all posts
Showing posts with label Index. Show all posts

Thursday, February 25, 2016

How to use INDEX & MATCH in Excel

In order to do a vertical lookup in Excel many users usually use VLOOKUP function. It’s understandable because VLOOKUP means Vertical Lookup J. And if you are offered to use INDEX MATCH functions instead of VLOOKUP you can ask "What do I need that for?". The point is that VLOOKUP is not the only lookup formula available in Excel, and its limitations to prevent you from getting the desired result in many situations. Excel's INDEX MATCH is more flexible and has certain features that make it superior to VLOOKUP in many respects.
Initially we consider INDEX & MATCH functions separately to understand how they work and then we’ll use them together to understand their key strengths. We will find examples that will help you easily solve complex tasks. Another benefit of using of INDEX & MATCH functions is that instead of just a vertical lookup, INDEX MATCH allows you to perform a matrix lookup, or “two-way lookup”. This combination formula may initially seem complex (because of its three individual formulas), but after you understand how they work, using of them will help you in many situations.

The INDEX function has the following arguments:
array:                  A range
      row_num:          A row number within the array argument
    column_num:    A column number within the array argument

If both row_num and column_num parameters are used, the INDEX function returns the value in the cell at the intersection of the specified row and column. For example, looking at the table below in the range A5:E55 we can use INDEX to return the capital of California with a formula as follows: =INDEX(A5:E55,6,2)

The result returned is Sacramento.
On its own the INDEX function is pretty inflexible because you have to hard key the row and column number, and that’s why it works better with the MATCH function.

The MATCH function has three arguments:

  1. lookup_value: The value (that you want to match in lookup_array).
If match_type is 0 and the lookup_value is text, this argument can include the wildcard characters * and ?.
  1. lookup_array: The range (that you want to search). This should be a one-column or one row range.
  2. [match_type]: An integer (–1, 0, or 1) that specifies how the match is determined.
     1 - find the largest value less than or equal to lookup_value
             (the list must be in ascending order)
     0 - find the first value exactly equal to lookup_value. Lookup_array
             (the list can be in any order)
    -1 -- find the smallest value greater than or equal to lookup_value.
             (the list must be in descending order)
    Note: If match_type is omitted, it is assumed to be 1.

Now we know the basics of these two functions, and start to use MATCH and
INDEX together. Below is the syntax for using this formula combination.
= INDEX ( array , MATCH ( lookup_value , lookup_array , 0 ) , MATCH (lookup_value , lookup_array , 0 ) )

And now, let us apply this formula in practice. Below, there is a list of the most populated counties in the world. Suppose, we want to know the number of population in the Japan in the year 2008:

OK, let's start on the formula. It’s a good practice to create a complex Excel formula with one or several nested functions. So let’s write each individual function first. Start by writing two MATCH functions that will return the row and column numbers for your INDEX function.

        Vertical match - you search through column B, (cells B3 to B12), for the value in cell H2 ("Japan"): MATCH($H$2,$B$3:$B$12,0).
This MATCH formula returns 10 because "Japan" is the 10th item in range $B$3:$B$12

Horizontal match - you search for the value in cell H3 ("2008") in row 2,
MATCH($H$3,$A$2:$E$2,0).

Now, put the above formulas inside the INDEX function:
=INDEX($A$3:$E$12, MATCH($H$2,$B$3:$B$12,0), MATCH($H$3,$A$2:$E$2,0)) and the result will  be 128.

 If we replace the MATCH functions with the returned numbers, the formula is much easier to understand: = INDEX($A$3:$E$12, 4, 10, 0))
Meaning, it returns a value at the intersection of the 4th row and 10th column in range A3:E12, which is the value in cell D12.

That's all! 


Tuesday, February 23, 2016

4 Reasons why Using of INDEX MATCH is better than using of VLOOKUP

Most of excel users prefer VLOOKUP formula to INDEX MATCH because as they think it’s a simpler. They don’t fully understand the advantages of using of INDEX MATCH formula. Just for info - Excel experts prefer INDEX MATCH to VLOOKUP. And below I will try to explain why.

Reason # 1 – Simpler to choose the necessary column
With the VLOOKUP you specify your entire table array, AND THEN you specify a column reference to indicate which column you want to pull data from.


You should specify entire table (AB6:E22) and then specify a column reference to indicate which column you want to pull data from.
And it can leads to errors when you have a large table and you need to count the number of columns you want. When you use INDEX MATCH, no such counting is required. In INDEX MATCH you directly select which column you want to return.


It’s a small difference, but this additional step leads to more errors. This error is especially prevalent when you have a large table array and need to visually count the number of columns you want to move over.  When you use INDEX MATCH, no such counting is required.



Reason # 2 – No problem when you insert new columns in a table
Any time you work with a large dataset, there’s a chance you’ll need to insert a new column.  With VLOOKUP, any inserted (or deleted) column will change the results of your formulas. The greatest benefit of using INDEX MATCH over VLOOKUP is the fact that, with INDEX MATCH, you can insert columns in your table array without distorting your lookup results.
Take the VLOOKUP example below.  Here, we’ve setup the formula to pull the Population value from our data table.  Because it is a VLOOKUP formula, we have referenced the 4th column.
If we insert a column in the middle of the table array, the new result is now “1850”; we are no longer pulling the correct value for Population and must change the column reference.
With INDEX MATCH you can insert and delete columns without worrying about updating every associated lookup formula.

Reason # 3 – Right to Left Lookup
With VLOOKUP, because you can only perform a left-to-right lookup, any new lookup key you add must be on the left side of your original table.  And every time you add a new key, you have to shift your entire dataset to the right by one column.  It can also causes the problems with existing formulas and calculations you’ve already created. As you can see from below picture, INDEX MATCH syntax doesn’t care whether lookup column is on the left or right side of your return column.


Reason # 4 – Lower Processing Need


Sometimes it’s required to lookup values for thousands of rows and hundreds of columns. When we added new column (or row) Excel would freeze up and take several minutes to calculate the return values. Replacing VLOOKUP formulas with INDEX MATCH to speed up the calculations.
The reason for this difference is that VLOOKUP requires more processing power from Excel because it needs to evaluate the entire table array you’ve selected.  With INDEX MATCH, Excel only has to consider the lookup column and the return column and Excel can process these formulas much faster.