+ Reply to Thread
Results 1 to 7 of 7

Count unique if criteria is met

  1. #1
    Registered User
    Join Date
    07-06-2015
    Location
    California
    MS-Off Ver
    2010
    Posts
    2

    Count unique if criteria is met

    I'm trying to count the number of unique values in a column if a certain name is present in another column.

    Example:

    Column A Column B
    Joanna ECO60610
    Joanna ECO60610
    Joanna ECO60610
    Ilona ECO56003
    Sylwia ECO59237
    Sylwia ECO59237
    Sylwia ECO59237
    Sylwia ECO59237
    Sylwia ECO59237
    Sylwia ECO59237
    Marta ECO59824
    Marta ECO59824
    Ilona ECO60593
    Ilona ECO59298

    For Joanna, the result would be 1
    For Ilona, the result would be 3
    For Sylwia, the result would be 1
    For Marta, the result would be 1

    I've been using the following function for the unique values: =Sum(1/COUNTIF(B:B,B:B)) validated by Ctrl+Shift+Enter
    The only way I could think of to do this is to split up the function by having an additional hidden column C with =SUM(1/COUNTIF(B:B,B#) and then in another cell, =SUMIFS(C#:C#,A#:A#,NAME)

    Can anyone help with combining this into one function?

    Thank you

  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: Count unique if criteria is met

    Try this formula

    =SUMPRODUCT(($A$2:$A$15=D2)/COUNTIF($B$2:$B$15,$B$2:$B$15&""))

    Row\Col
    A
    B
    C
    D
    E
    2
    Joanna ECO60610 Joanna
    1
    3
    Joanna ECO60610 Ilona
    3
    4
    Joanna ECO60610 Sylwia
    1
    5
    Ilona ECO56003 Marta
    1
    6
    Sylwia ECO59237
    7
    Sylwia ECO59237
    8
    Sylwia ECO59237
    9
    Sylwia ECO59237
    10
    Sylwia ECO59237
    11
    Sylwia ECO59237
    12
    Marta ECO59824
    13
    Marta ECO59824
    14
    Ilona ECO60593
    15
    Ilona ECO59298
    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
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count unique if criteria is met

    Try this...

    Data Range
    A
    B
    C
    D
    E
    1
    ------
    ------
    ------
    ------
    ------
    2
    Joanna
    ECO60610
    Joanna
    1
    3
    Joanna
    ECO60610
    Ilona
    3
    4
    Joanna
    ECO60610
    Sylwia
    1
    5
    Ilona
    ECO56003
    Marta
    1
    6
    Sylwia
    ECO59237
    7
    Sylwia
    ECO59237
    8
    Sylwia
    ECO59237
    9
    Sylwia
    ECO59237
    10
    Sylwia
    ECO59237
    11
    Sylwia
    ECO59237
    12
    Marta
    ECO59824
    13
    Marta
    ECO59824
    14
    Ilona
    ECO60593
    15
    Ilona
    ECO59298


    This array formula** entered in E2 and copied down:

    =SUM(IF(FREQUENCY(IF(A$2:A$15=D2,MATCH(B$2:B$15,B$2:B$15,0)),ROW(B$2:B$15)-ROW(B$2)+1),1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    EDIT: Assumes no empty cells within the data range.
    Last edited by Tony Valko; 07-07-2015 at 08:05 AM.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count unique if criteria is met

    Quote Originally Posted by AlKey View Post
    Try this formula

    =SUMPRODUCT(($A$2:$A$15=D2)/COUNTIF($B$2:$B$15,$B$2:$B$15&""))
    Try that formula on this data:

    Data Range
    A
    B
    1
    ------
    ------
    2
    Joanna
    ECO60610
    3
    Joanna
    ECO60610
    4
    Joanna
    ECO59237
    5
    Ilona
    ECO56003
    6
    Sylwia
    ECO59237
    7
    Sylwia
    ECO59237
    8
    Sylwia
    ECO59237
    9
    Sylwia
    ECO59237
    10
    Sylwia
    ECO59237
    11
    Sylwia
    ECO59237
    12
    Marta
    ECO59824
    13
    Marta
    ECO59824
    14
    Ilona
    ECO60593
    15
    Ilona
    ECO59298

  5. #5
    Registered User
    Join Date
    07-06-2015
    Location
    California
    MS-Off Ver
    2010
    Posts
    2

    Re: Count unique if criteria is met

    Thank you very much to both of you.

    Both formulas work on the data I provided but there's issue with the =SUMPRODUCT(($A$2:$A$15=D2)/COUNTIF($B$2:$B$15,$B$2:$B$15&"")) if you change the value in B4 to match B6. Why is that?

  6. #6
    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: Count unique if criteria is met

    It should work now.

    =SUMPRODUCT((A$2:A$15=D2)/COUNTIFS(A$2:A$15,A$2:A$15,B$2:B$15,B$2:B$15&""))

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count unique if criteria is met

    Just some FYI...

    The SUM(IF(FREQUENCY array version is more efficient (faster to calculate) especially on large data sets.

+ 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. Count Unique with Criteria
    By david0985 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-20-2015, 07:36 PM
  2. [SOLVED] Count unique entries based off unique criteria in another column
    By hambly in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 06-11-2014, 03:33 PM
  3. [SOLVED] COUNT IF UNIQUE VALUE and CRITERIA
    By Charoum in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-28-2013, 01:51 AM
  4. [SOLVED] Unique Count with Criteria
    By MitchC in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-28-2013, 05:49 AM
  5. [SOLVED] changing a current mod (count unique visible cells ->count unique visible cells criteria
    By liranbo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2012, 03:58 AM

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