Excel here

Monday, September 04, 2006

How to Get Unique Items using Excel

I recently had to perform some analysis on a set of insurance companies in certain geography. After searching the net I found such list of companies operating in that continent. But the problem is,

  • These companies are listed multiple times, one time for each of their geographical area of operation.
  • I cannot count each company only once since there is geography specific operational data in that list.
  • But at the same time, information pertaining to organization like total sales, strategy etc. are common to all the subsidiaries / separate entities of a company.
  • There are too many companies to do the manual grouping of companies

I think this type of problems are fairly common in business analytics. So here is a relatively simple solution for getting unique list of companies without losing any information or writing macros. See the example for yourself.

Lets take an example of employee data. You have fields like Person Name (sometimes unique), Previous employment, Previous workplace, Previous Salary. Now, if person Anand worked in more than one place earlier, there will be more than one rows with his name. But for details like DOB, SSN etc. there wont be multiple rows. So you need to know how many uniques rows are there in that huge list. Detailed Steps:

  1. Enter / copy the data

  2. Sort the list on person name

  3. In the column next to prev-company enter the following formula in E2
    =IF(OR(LEFT(B2,SEARCH(" ",B2))=LEFT(B3,SEARCH(" ",B3)),LEFT(B2,SEARCH(" ",B2))=LEFT(B1,SEARCH(" ",B1))),LEFT(B2,SEARCH(" ",B2)),B2)

    Copy - paste the formula in all the cells in the list for the column. You will see the followin result.

  4. Now create one more column next to Unique Name with heading Unique?. Paste the following formula in the F2. Apply the formula to all the cells in the list.


    Now, you would see the list like this.

  5. Now sellect the top row and apply "auto filters" [Data->Filter->Auto-Filter] And select 1 in the Unique? column. You will see all the unique names. You can copy paste this list in another sheet/work-book and work with it or assign corresponding codes to each of the unique items in this list.

To summerize:

1. Sort your list first.
2. Get the unique parts like first word / first number etc in another column. In my case I had to use first word.
3. Compare consecutive rows and mark the differences. Now you know how many unique items you have.

Comments / Any better ways of doing this are always welcome.


  • It might be obvious for some but for copying the unique rows after auto filter, one will have to use
    Edit->GoTo->Special->Visible Cells only
    To copy those unique rows!

    Btw an excel blog will be helpful for many out there :)

    By Blogger Akshat, at 9/04/2006 04:14:00 AM  

  • Yeah, you are right. I am using Excel 2003, so you can directly copy-paste and it will paste only visible cells.

    By Blogger Chandoo, at 9/04/2006 10:10:00 AM  

  • It may be necessary to use formulas, in some situations, but Excel's Pivot Table is MUCH faster, if you can use it.

    You can highlight the table (including headings) and select Data Pivot Table...

    For step 1, press Next to accept the defaults.
    For step 2, press Next
    On step 3, click the Layout button. Then drag the "Name" field to BOTH the "ROW" and the "DATA" section, and click OK
    Click Finish

    Excel will give you the count for each name on a new worksheet. There 's a further advantage here: the table does NOT need to be sorted first.

    By Blogger Stan Scott, at 1/06/2009 10:51:00 AM  

  • What has been stated here in this post is only very customized to you as a user. There are a lot of things that have gone into assumptions, primary one being, they are sorted in order!

    @Stan: PT are a good way, but I think there are much better ways to do this, those which can be extended for other uses as well. I will be blogging this pretty soon, since there is so much information on this, and some very good sites too.

    My blog: http://onestopanalytics.wordpress.com

    By Blogger Arun, at 5/26/2009 03:49:00 AM  

  • Invest in Stock market after joining Epic Research for the best Stock tips and advises.

    By Blogger Ram Katariya, at 9/12/2016 02:47:00 AM  

Post a Comment

<< Home