Monday, 31 December 2012



In the previous tutorial we have seen that VLOOKUP can be used to extract the data.

Let’s explore the formula of VLOOKUP in detail VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

Lookup_value is the value to be searched in the table which has all the required data to be searched.
For example, it can be the Name of the person. Based on the name of the person, other details about the person can be extracted from the table which contains the desired data.

The table_array refers to the table from which we want the desired data.

The values in the first column of table_array are the values searched by lookup_value.

The first column in both the tables i.e., the table where you want to extract the data and the table where you want the desired data should be the same.
For example, in both the tables Name should be the first column if you want to extract the data according to the Name.

Col_index_num refers to the number of the column (belonging to the table_array) from which you want the data.
For example, I want the data related to the Age of the person from the name of the person. Assume Age is the second column. So the col_index_num should be 2.

Range_lookup - A logical value that specifies whether you want VLOOKUP to find an exact match or an approximate match. Specify FALSE for exact match and TRUE for approximate match.

Now the problem with the previous method is that there can be a case where the lookup_value might not be unique. For example, consider a table consisting of Name, Occupation and Age of the people and another table consisting the Name, Occupation and Salary information. I want to extract the data related to the Salary from the second table. I can use Name as the lookup_value. But two people can have the same Name. Hence, Name is no more the unique identifier.
In such cases, key can be used.
Key is formed by simply merging the information such that it should be unique.

Let’s take another example:

Goal: VLOOKUP using Key.

Solution: Consider a table (Table 1) as below in the first sheet of your workbook.



 In this table (Table 1) we have information related to the Name, Standard and the Age of the student.
Consider another table (Table 2) as below



This table has additional information related to the Subject each student has opted for.

Our aim is to get the exact information related to the Subjects (as per the student has opted for) in Table 1 from Table 2.

Create a key as shown below in Table 1.



This key will function as a unique identifier. Do drag and fill the remaining rows in the manner shown below and do perform a copy and paste special to keep only the values.



In a similar manner create a key in the second table.
To perform this first insert another column as shown below. This column will have unique key as formed previously.



The Table 2 after forming the key is as shown below. Again drag and perform copy and paste special to keep only the values.


Now we are all set to perform VLOOKUP. Name a column Subject in Table 1 besides the Key column. This column will have the data related to the Subject opted by a particular student.



Perform the below steps (VLOOKUP) to get the required data.

Step 1:



Step 2: Table_Array is Table 2 with Key and Subject column as below


Step 3: 
Column number should be specified from which you want the data. Subject in this case is column number 2.
Check the formula bar for the column number.



Step 4: Specify False for an exact match.

The entire formula is as follows:

=VLOOKUP(D2,Sheet2!D1:E6,2,FALSE)

Drag and perform paste special to get all the values. The Table 1 after performing VLOOKUP is as shown below.



One can notice that we had data related to Andy studying in the 2nd standard as well as the 3rd standard. Due to the unique key the correct data was extracted as expected.

After removing the Key column (as it is not required any longer) Table 1 is as follows:



That's the way/key to use VLOOKUP effectively!! :)






Monday, 24 December 2012



Excel has something called VLOOKUP to offer. If your work involves lot of analysis then VLOOKUP and Pivot table can help you a lot.
This function is the most popular among the so called geek community!  :P
Nobody can deny that it reduces your work to half or even lesser. 
Quantitatively you will spend less on a table full of numbers and Qualitatively you will have more time to learn new things or spend time on something good.
Anyway going back

Goal: Use VLOOKUP on a table

Solution:

1. It is always advisable to use the TRIM function to remove all the trailing spaces.

2. Here is my data table as seen in excel





Table with data


Now, I want to get the additional details about the subjects that each student has opted for. This data is present in another table (Sheet2) in the below form.




Another Table with additional data on the subject opted



3. Lets use VLOOKUP now!! How do we do that?

Simple, create a column named Subject in the first sheet. Done!! 

Now, copy and paste the formula (you can type it as well to learn it better) =VLOOKUP(A2,Sheet2!A:C,3,FALSE).
Eureka! Tom has opted for Maths! But how exactly this works?
Answer is simple.

VLOOKUP stands for Vertical Lookup. The formula requires the value (contained in cell A2) that you want to lookup in the table containing the desired data (in our example data related to the subject is in the second table). But how would excel know that we require data related to the third column, i.e. Subject. For that we need to enter the column number which is the third field in the formula. The last field tells excel whether we want an approximate match or exact match. False means I want the Exact match. Vertical Lookup is for extracting the data from the desired column of the table.


We can use VLOOKUP to extract the desired data from the table containing it. If I have the data related to the students belonging to all the standards and I want to extract the data related to the students belonging to the first standard then I can use VLOOKUP to get the desired details.


Lets see the output for the entire table after dragging the fill handle.




Final Table with the subject data extracted!


Now we have the required data with us! This was just the basic tutorial related to VLOOKUP. There is more to it!! The next lesson/tutorial will give you the exact data in a more effective and reliable way.

Saturday, 21 April 2012

Goal-  Comparing Tables using Excel

Solution-
1. Make sure that are no trailing or extra spaces. One can either use find and replace function to remove the spaces or Trim or Clean Function.

2.
A              B                    C                D
Names Capability Location
John Testing  A1
Tom SAP A2
Tim Testing  A1
Alan Java A2
Alex Testing  A1
Ron Mainframe A3
Dan Oracle A5

Table1 is in Sheet1

A              B                  C                 D
Name Capability Location
Dan Oracle A5
Tom Testing  A2
Tim Testing  A1
Alan Java A2
Ron Mainframe A3
John Testing  A1

Table2 is in Sheet2.

I have considered Table2 as my reference table and made the comparison accordingly. 

3. To compare use the function COUNTIFS on an empty cell in column D of sheet1 as follows:

=COUNTIFS(Sheet2!A:A,Sheet1!A2,Sheet2!B:B,Sheet1!B2,Sheet2!C:C,Sheet1!C2)>0

Here my First Range is the First Column (Name Column) of the Table2 and my First criteria is the cell containing the value John in Table1.
Second Range is the Second Column (Capability) and Second criteria is the cell containing the value Testing in Table1.
Similarly, Third Range is the Third Column (Location) and the Third criteria is the cell containing the value A1 in Table1.

4. The idea is to compare the Name, Capability and Location details of John existing in Table1 with that in Table2. If they match then the COUNTIFS Function returns the count which is nothing but the no. of times the criteria gets satisfied. In our case that will be 1 as there is only one record of John in Table2 matching with the record in Table1.

>0 part lends us a TRUE or FALSE Statement.

If TRUE statement is the output then there are records in Table2 matching with the ones in Table1 else they are not present.

This simplifies the task of Comparison considerably.

5. Just drag and drop the fill handle ( + sign) from the cell in which you got TRUE\FALSE for the first comparison in column D for comparison of the entire table. You don't have to write the formula again.

THATS IT!!

Final Output for the above tables will be as follows:

A              B                    C               D

Names Capability Location Compare
John Testing  A1 TRUE
Tom SAP A2 FALSE
Tim Testing  A1 TRUE
Alan Java A2 TRUE
Alex Testing  A1 FALSE
Ron Mainframe A3 TRUE
Dan Oracle A5 TRUE

And do copy and paste special so that values remain and not the formula.

6. Time to Run Home Early :-D
If you want to get your output as quickly as possible using excel then learn to use it Smartly.
Eg. If Find and Replace removes all the spaces in a cell then do not spend time on using the trim function on each column.

There can be times when you have to meet a specific deadline and you don't have time to explore Excel.
This may lead to long working Hours and lot of frustration. It has happened with me.
But while at home I try to learn as much as possible and try to remember it so that the next time I am given an Assignment I deliver it before time :D
No one can run away from Excel (at least in IT) and the moment you delve into it you would want to know more!!