+ Reply to Thread
Results 1 to 11 of 11

count number of values in one column if unique value in another.

  1. #1
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    count number of values in one column if unique value in another.

    I have two formula's I'm trying to work on. The first needs to count the number of "N" in one column if the value in the first column is unique.

    i.e. if I had:

    column A B
    1 N
    2 Y
    1 N
    3 N

    I'd like it return 2 as there are 2 N's in column B which relate to unique values in column A. I have been trying to use a countif formul, but think I've not quite got it right as it returns zero. I have been trying the following:

    =COUNT(IF(COUNTIF(A1:A4,A1:A4)=1, B1:B4, "N"))

    The second forumla I need is a step further and would count the number of "Y" in a third column if the secon column is "N" and the first column is a unique value...

    column A B C
    1 N Y
    2 Y Y
    1 N Y
    3 N Y

    So again in this example the result I'd want is 2!

    Any help would be great!

    Thanks,
    James
    Last edited by j.farr3ll; 08-14-2013 at 08:54 AM.

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: count number of values in one column if unique value in another.

    Hi,

    Sorry if I'm missing something, but in your first example I see two values which are unique (2 and 3), but only one of which has an "N" in the corresponding row, so using your logic I would have a result of 1, not 2.

    Please could you clarify?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: count number of values in one column if unique value in another.

    Ah ok maybe I didn't explain myself properly. I want to exclude duplicates essentially.

    So from the example I would want to return 2 as 1 and 3 have N, but not simply count the N's as this would return 3.

    1 N
    2 Y
    1 N
    3 N

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: count number of values in one column if unique value in another.

    Ok, can you try these two and get back to me?

    Assuming your data is in the range A2:C11, this array formula (confirm with CTRL+SHIFT+ENTER, not just ENTER), should give you your first desired result:

    =SUMPRODUCT(--(FREQUENCY(IF($B$2:$B$11="N",$A$2:$A$11),ROW(INDIRECT("1:"&MAX(IF($B$2:$B$11="N",$A$2:$A$11)))))>0))

    And this (non-array, this time) should give you your second:

    =SUMPRODUCT(($C$2:$C$11="Y")*($B$2:$B$11="N")*(COUNTIF($A$2:$A$11,$A$2:$A$11)=1))

    Regards

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

    Re: count number of values in one column if unique value in another.

    Try

    =SUMPRODUCT((A1:A4<>"")/COUNTIF(A1:A4,A1:A4)*(B1:B4="N"))

    and

    =SUMPRODUCT((A1:A4<>"")/COUNTIF(A1:A4,A1:A4)*(B1:B4="N")*(C1:C4="Y"))

    Edit: Will not work if your range has blanks
    Last edited by Ace_XL; 08-14-2013 at 04:04 PM.
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  6. #6
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: count number of values in one column if unique value in another.

    Thanks for taking your time on this.

    When I apply the first formula to my larger dataset I get a value error. The second works, but makes the calculation speed so slow that the dataset become intolerable.

    Is there any way to do this without excel slowing down?

    My data is in the following ranges:

    A5:A25005
    E5:E25005
    F5:F25005

    Many Thanks,
    James

  7. #7
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: count number of values in one column if unique value in another.

    Sorry I should specify my response was to XOR LX.

    I've also tried Ace_XL's formulas and they result in #DIV/0! errors. Could this be because there are blanks in the dataset?

  8. #8
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: count number of values in one column if unique value in another.

    Ok coming back to this... I think my excel was just playing up. Sorry for wasting people's time.

    XOR LX's solutions seem to work great!

    Thanks,
    James

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: count number of values in one column if unique value in another.

    Hi,

    I assume you entered the first as an array formula, as I specified?

    I've just tried both on a dataset of two columns of 25,000 rows and no issues whatsoever - a fraction of a second to calculate. What else have you got going on in your sheet, formula-wise? Have you tried running this scenario with just those two columns, as I did?

    It would be difficult for me to help you further without seeing your actual sheet.

    Regards

  10. #10
    Registered User
    Join Date
    07-28-2010
    Location
    london, england
    MS-Off Ver
    Excel 2007
    Posts
    91

    Re: count number of values in one column if unique value in another.

    Hi XOR LX,

    As you say it seems to be working fine now, so many thanks again for your assistance. I wouldn't have been able to work those formuals out on my own in months and months!

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: count number of values in one column if unique value in another.

    No worries. Glad I could help.

+ 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. Replies: 4
    Last Post: 07-16-2013, 09:45 AM
  2. Replies: 12
    Last Post: 07-03-2012, 04:50 PM
  3. Count Unique Values In One Column Basis Unique Values in Another Column
    By shez_raz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-07-2012, 01:55 AM
  4. Count number of unique values using Sumproduct
    By tomlancaster in forum Excel General
    Replies: 2
    Last Post: 12-02-2011, 10:35 AM
  5. [SOLVED] Count number of Unique values
    By Alan in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-06-2005, 05:06 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