+ Reply to Thread
Results 1 to 11 of 11

How to count distinct values in a column, categorized by values in another column.

  1. #1
    Registered User
    Join Date
    05-29-2013
    Location
    Murfreesboro, TN
    MS-Off Ver
    Excel 2007
    Posts
    11

    How to count distinct values in a column, categorized by values in another column.

    Hi,

    Just had this problem, and I made up an example to explain it. Please download the attached Excel file.

    From the example, Table 1 is to store the raw data. Say we have different car models, A to L. The 2nd column gives the makes of the models. (Here the data type could be numeric.) The 3rd column shows the types of the models.

    Table 2 will do the calculation and show the results. Column 2 should show how many different types each make contains. For instance, there should be only 1 type for Jeep, which is the SUV.

    Thanks for the help!

    Joe
    Attached Files Attached Files
    Last edited by zhuowang1980; 07-15-2013 at 04:00 PM.

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: How to count distinct values in a column, categorized by values in another column.

    In F3

    =SUMPRODUCT(($B$3:$B$14=E3)/COUNTIFS($B$3:$B$14,$B$3:$B$14,$C$3:$C$14,$C$3:$C$14))

    Copy down
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Registered User
    Join Date
    05-29-2013
    Location
    Murfreesboro, TN
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How to count distinct values in a column, categorized by values in another column.

    Thanks so much! It worked!


    Quote Originally Posted by Ace_XL View Post
    In F3

    =SUMPRODUCT(($B$3:$B$14=E3)/COUNTIFS($B$3:$B$14,$B$3:$B$14,$C$3:$C$14,$C$3:$C$14))

    Copy down

  4. #4
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How to count distinct values in a column, categorized by values in another column.

    This should work:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  5. #5
    Registered User
    Join Date
    05-29-2013
    Location
    Murfreesboro, TN
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How to count distinct values in a column, categorized by values in another column.

    Thanks again for the answer. Could you please explain how this formula works. I'm trying to apply the formula to the Excel Table cells, unfortunately it didn't work out. Please see the attached file. I used the Excel Table, and used the column name instead of cells to set up the formulas, since Table 1 will keep growing, and the number of rows will be very big.



    Quote Originally Posted by Ace_XL View Post
    In F3

    =SUMPRODUCT(($B$3:$B$14=E3)/COUNTIFS($B$3:$B$14,$B$3:$B$14,$C$3:$C$14,$C$3:$C$14))

    Copy down
    Attached Files Attached Files
    Last edited by zhuowang1980; 07-15-2013 at 05:34 PM.

  6. #6
    Registered User
    Join Date
    05-29-2013
    Location
    Murfreesboro, TN
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How to count distinct values in a column, categorized by values in another column.

    Thanks so much!

    Quote Originally Posted by newdoverman View Post
    This should work:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How to count distinct values in a column, categorized by values in another column.

    I found that if you replace the Table references with Sheet name references, the "system" works. I found this out by changing the original range to a table and also the result range to a table and then cut and pasted the second table to a new sheet, the cell references retained the sheet names and cell references.

    I too would like a full explanation of this SUMPRODUCT formula. It looks strange but it sure works.

  8. #8
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How to count distinct values in a column, categorized by values in another column.

    I made the tables work! It involved using named ranges. Take a look. I selected Table1 and then on the Formula Tab clicked on Create from Selection. This created named ranges from all the table columns.
    Attached Files Attached Files
    Last edited by newdoverman; 07-15-2013 at 06:31 PM.

  9. #9
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How to count distinct values in a column, categorized by values in another column.

    The formula in table2 can be shortened to this:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-29-2013
    Location
    Murfreesboro, TN
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How to count distinct values in a column, categorized by values in another column.

    This works! Thanks so much newdoverman!!!

    Quote Originally Posted by newdoverman View Post
    The formula in table2 can be shortened to this:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  11. #11
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: How to count distinct values in a column, categorized by values in another column.

    You are welcome and thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1