+ Reply to Thread
Results 1 to 12 of 12

CountIFs results excluding duplicates

  1. #1
    Registered User
    Join Date
    01-07-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    54

    CountIFs results excluding duplicates

    Consider the 2 columns that I have below:
    SubjID Sample_Type
    ABC12 bld
    ABC13 bld
    ABC14 bld
    ABC15 bld
    ABC12 bld
    ABC12 bld
    ABC12 ser
    ABC12 ser
    ABC13 ser
    ABC13 ser
    ABC12 urn
    ABC15 urn

    Now, how do I count the number of unique sample types for each subjID? For example, ABC12 should have 3, and ABC13 should have 2. Thanks.

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: CountIFs results excluding duplicates

    Hi and welcome to the forum

    Maybe this

    =A2&B2 in C2 and down

    to get unique vales

    in E2 and down.

    =INDEX($C$2:$C$13,MATCH(0,INDEX(COUNTIF($E$1:E1,$C$2:$C$13),,),))

    in D2 and down

    =COUNTIF($C$2:$C$13,E2)

    A
    B
    C
    D
    E
    1
    Value 1 Value 2 Count
    2
    ABC12 bld ABC12bld
    3
    ABC12bld
    3
    ABC13 bld ABC13bld
    1
    ABC13bld
    4
    ABC14 bld ABC14bld
    1
    ABC14bld
    5
    ABC15 bld ABC15bld
    1
    ABC15bld
    6
    ABC12 bld ABC12bld
    2
    ABC12ser
    7
    ABC12 bld ABC12bld
    2
    ABC13ser
    8
    ABC12 ser ABC12ser
    1
    ABC12urn
    9
    ABC12 ser ABC12ser
    1
    ABC15urn
    10
    ABC13 ser ABC13ser
    11
    ABC13 ser ABC13ser
    12
    ABC12 urn ABC12urn
    13
    ABC15 urn ABC15urn
    Last edited by AlKey; 01-07-2014 at 07:20 PM.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Registered User
    Join Date
    01-07-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: CountIFs results excluding duplicates

    Thanks AlKey. I'm hoping to see a less steps solution.

  4. #4
    Registered User
    Join Date
    01-07-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: CountIFs results excluding duplicates

    AlKey, today I noted a problem with your fomula above. The count number only works for the first occurence. If you look at subject ABC 12, the first occurence is 3, but the second is 2 and third is 1. That doesn't work. Thanks for trying though.

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: CountIFs results excluding duplicates

    I don't think I understand you. Do you need the total of "ABC 12", the sum of (3+2+1)? Can you provide what exactly you would like to see by showing the final result and layout?

  6. #6
    Registered User
    Join Date
    01-07-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: CountIFs results excluding duplicates

    This is what I want to see:
    Subject_ID sample type # of unique sample type
    ABC12 BLD 3
    ABC13 BLD 2
    ABC14 BLD 1
    ABC15 BLD 2
    ABC12 BLD 3
    ABC12 BLD 3
    ABC12 SER 3
    ABC12 SER 3
    ABC13 SER 2
    ABC13 SER 2
    ABC12 URN 3
    ABC15 URN 2

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: CountIFs results excluding duplicates

    Please see attached file
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-07-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: CountIFs results excluding duplicates

    Is there any simpler way to do this as I have a table of thousand hundred of samples with all kinds of different sample types? Thanks.

  9. #9
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: CountIFs results excluding duplicates

    hi there. i looked at your other post here & noted that you mentioned:
    I looked at your post and tried to learn different formulas. It took me a while to understand Sixsenth formula. It seems too complicated & sophisticated for me. I like anything simple and easy, so I came up with a shorter & more mediocre one
    so i'm a little confused. Alkey's solution seems to break it down for you. if you want something with less steps, it's going to be more complicated. try this array formula in row 2:
    =SUM(IF(FREQUENCY(IF($A$2:$A$13=A2,MATCH($B$2:$B$13,$B$2:$B$13,0)),ROW($B$2:$B$13)-ROW($B$2)+1)>0,1))
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    copy down. i don't know if you really need the numbers to repeat. you could create a unique list somewhere & just use the same formula, not referring to A2 but the unique list instead. the unique list can be done using Remove Duplicates or another array formula. you can check out the link in my Signature below on Tips & Tutorials I Compiled & download the file. it's in sheet 2

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  10. #10
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: CountIFs results excluding duplicates

    @benishiryo

    Very nice approach to solve this puzzle! Thanks for helping out

    Hmm...was trying to give you some Rep but the system wouldn't allow
    Last edited by AlKey; 01-08-2014 at 11:00 PM.

  11. #11
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: CountIFs results excluding duplicates

    @AlKey:
    no worries about it. =)
    you cannot give rep to the same person consecutively i think.

    @Excel_learner:
    by the way, i don't know if "a table of thousand hundred of samples" is referring to hundred of thousands? my formula will hang your computer if so. if that's really the case, you should consider PowerPivot since you are using Excel 2010. it's too huge a topic to share with, but the name alone should give you a headstart to start googling. The Pivot from there has a ready-made Distinct Counts for you.

  12. #12
    Registered User
    Join Date
    01-07-2014
    Location
    Philadelphia
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: CountIFs results excluding duplicates

    @Benishiryo,
    Thank you so much for your help and tips. I'm inherited this messy spreadsheet from someone else and trying to apply different formulsa in response to queries from upper management. I'm not very familiar with pivot table and do not think it's applicable for my spreadsheet since it's far more complicated than just subjID and sample type. I'm thinking about separate it into different tables and move them to MS Access but haven't got time to do it.
    Having unique subjID in a separate sheet is a great idea. My subjID column sometimes can be blank. Having "0" and "#N/A" at the end of the new list is fine, but I do not like to have it in the middle of the list. Can your formula eliminate this situation? Also, the main spreadsheet keeps growing. Is there any way I can parse all the sample types for each unique subjID in the same row?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. COUNTIFS with no duplicates
    By dasseya1 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 08-23-2013, 04:09 AM
  2. [SOLVED] COUNTIFS and excluding duplicates
    By lawend in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-08-2013, 03:39 PM
  3. COUNTIFS and Duplicates
    By connorwfarrell in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-05-2012, 04:17 AM
  4. Countifs results excluding duplicates
    By jeffreybrown in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-28-2011, 12:22 PM
  5. Excluding duplicates
    By analyst10 in forum Excel General
    Replies: 3
    Last Post: 11-22-2010, 08:19 PM

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