+ Reply to Thread
Results 1 to 7 of 7

Count distinct values with criteria

  1. #1
    Registered User
    Join Date
    07-29-2008
    Location
    NY
    Posts
    3

    Count distinct values with criteria

    I'm running into a little trouble counting distinct values while applying a criteria. For example, there is a list of names with possible duplicate values, name this range "Rng1". Each value in Rng1 is associated with either "Sales", "Marketing", or "Admin." How would you use one formula to count the number of distinct values in Rng1 that correspond to "Sales"?

    Thanks in advance!

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

    =SUM(IF(FREQUENCY(IF(Rng2="Sales",IF(Rng1<>"",MATCH(Rng1,Rng1,0))),ROW(Rng1)-MIN(ROW(Rng1))+1),1))

    confirmed with CTRL+SHIFT+ENTER

  3. #3
    Registered User
    Join Date
    07-10-2008
    Location
    India
    Posts
    17
    May be
    =SUMPRODUCT(--(rng1="sales")/COUNTIF(A2:A10,A2:A10&""))
    where A2:a10 - names
    best wishes
    Sreedhar

  4. #4
    Registered User
    Join Date
    07-29-2008
    Location
    NY
    Posts
    3
    Thanks all! Worked wonders!

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by yshridhar
    =SUMPRODUCT(--(rng1="sales")/COUNTIF(A2:A10,A2:A10&""))
    Note: this might not give the correct result if you have the same name associated with different categories

  6. #6
    Registered User
    Join Date
    07-29-2008
    Location
    NY
    Posts
    3
    Is it possible to do the same thing with 2 criteria? For example, how would you count distinct values in Rng1 that corresponded to "Sales" in Rng2 AND "2007" in a new range Rng3?

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    You could tweak my suggested formula like this

    =SUM(IF(FREQUENCY(IF(Rng2="Sales",IF(Rng3=2007,IF(Rng1<>"",MATCH(Rng1,Rng1,0)))),ROW(Rng1)-MIN(ROW(Rng1))+1),1))

    still confirmed with CTRL+SHIFT+ENTER

    Note: I assume that 2007 in Rng3 is a number not a formatted date

+ 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