+ Reply to Thread
Results 1 to 9 of 9

Using Countif to return un-duplicated instances

  1. #1
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Using Countif to return un-duplicated instances

    In one column I have unique numerical IDs which could be duplicated up to three times. In another column I have the inputs "Yes" and "No" which correspond randomly to these IDs.

    In a third column I would like to return an affirmative output for the first instance of "Yes" for each unique ID code.

    For instance:

    Column A

    23
    23
    23
    4
    4
    6

    Column B

    No
    No
    Yes
    Yes
    Yes
    No

    Desired Column C

    0
    0
    1
    1
    0
    0
    Last edited by dforte; 11-19-2010 at 08:59 PM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Using Countif to return un-duplicated instances

    Assuming data starts at row 2 try this formula in C2 copied down

    =(COUNTIFS(A$2:A2,A2,B$2:B2,"Yes")=1)+0
    Audere est facere

  3. #3
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Using Countif to return un-duplicated instances

    Not quite.. I think it is on the right track with the countifs stmt, but it seems to be returning an affirmative output more than it should.

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Using Countif to return un-duplicated instances

    I believe that formula returns the required results for your example. Can you give me an example where it doesn't work?

  5. #5
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Using Countif to return un-duplicated instances

    Maybe you could just clarify the formula you presented earlier

    =(COUNTIFS(A$2:A2,A2,B$2:B2,"Yes")=1)+0

    Is this correct?

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Using Countif to return un-duplicated instances

    Yes, if you put that in C2 and copy down, given that your other data starts at row 2 you should get the output that you requested, with 1 for an affirmative. If you want you could use just

    =COUNTIFS(A$2:A2,A2,B$2:B2,"Yes")=1

    for TRUE/FALSE results

  7. #7
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Using Countif to return un-duplicated instances

    For some reason it is not working: here is the actual information I have in the cells:

    Column A

    51560
    69015
    47599
    47599

    Column B


    Yes
    Yes
    Yes
    No

    Column C's Output with the following formula copied down: =COUNTIFS(A$2:A2,A2,B$2:B2,"Yes")=1


    TRUE
    TRUE
    TRUE
    TRUE

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Using Countif to return un-duplicated instances

    Sorry, I didn't consider that possibility so the formula I suggested would be incorrect in some circumstances......

    This will fix it.....

    =AND(COUNTIFS(A$2:A2,A2,B$2:B2,"Yes")=1,B2="Yes")

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Using Countif to return un-duplicated instances

    =--IF(B2="no",FALSE,COUNTIFS($A$2:A2,A2,$B$2:B2,"yes")=1)
    hmm i see above works fine!
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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