+ Reply to Thread
Results 1 to 5 of 5

Formulas to sum distinct values with condition "any" and "all"

  1. #1
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Formulas to sum distinct values with condition "any" and "all"

    See attached.

    I have a table with location, name and condition (category) fields. On the next sheet, I have a working formula to calculate the number of distinct names (don't count repeated names within the same location) for each location in column B.

    What I need next is a formula to calculate the same (number of distinct names), but only count IF at least 1 of the corresponding names also has category 'B' - the group of names may have more than one 'B', but is only counted once. I think I have that formula correct in column C (gray highlight), but you can double check (thank you). Finally, and this is where I know my formula is incorrect (light blue highlight), a distinct name count where ALL the names are category 'A' (no 'Bs' or any other category - my sample only has 2 categories, but my actual data set has a few more categories).

    Sample C.xlsx

    EDIT - posted in correct forum with correct attachment.
    Last edited by HeyInKy; 06-30-2017 at 01:02 PM.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Formulas to sum distinct values with condition "any" and "all"

    =SUM(--(IFERROR(MATCH(Table1[Name],IF(Table1[Location]=$A3,Table1[Name]),),)=ROW(Table1[Location])-1)) for BB
    =SUM(--(IFERROR(MATCH(Table1[Name],IF((Table1[Location]=$A3)*(Table1[Category]=C$2),Table1[Name]),),)=ROW(Table1[Location])-1)) for BB CC
    in C2: B, D2: A
    Attached Files Attached Files
    Last edited by tim201110; 06-30-2017 at 02:05 PM.

  3. #3
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Formulas to sum distinct values with condition "any" and "all"

    So I'm trying to plug this into my sheet... the second formula I put into C2 (and changed $A3 to $A2, changed C$2 to C$1, and then changed my text in C1 to "B" and it seems to come up with correct answers as my existing formula... but the other one, your first,I can't decipher what to do with. Any further guidance?

  4. #4
    Forum Expert Tsjallie's Avatar
    Join Date
    09-15-2012
    Location
    NL
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2,077

    Re: Formulas to sum distinct values with condition "any" and "all"

    Try this array formula in cell D2 and drag down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Cheers!
    Tsjallie




    --------
    If your problem is solved, pls mark the thread SOLVED (see Thread Tools in the menu above). Thank you!

    If you think design is an expensive waste of time, try doing without ...

  5. #5
    Forum Contributor
    Join Date
    09-18-2015
    Location
    Republic of Korea
    MS-Off Ver
    2010
    Posts
    314

    Re: Formulas to sum distinct values with condition "any" and "all"

    B2 --> =COUNT(MATCH(ROW(Table1[Name])-1,MATCH(Table1[Name],Table1[Name],0)*(Table1[Location]=A2),0))
    C2 --> =COUNT(MATCH(ROW(Table1[Category])-1,MATCH(Table1[Name],Table1[Name],0)*(Table1[Location]=A2)*(Table1[Category]="B"),0))
    D2 --> =COUNT(MATCH(ROW(Table1[Category])-1,MATCH(Table1[Name],Table1[Name],0)*(Table1[Location]=A2)*(Table1[Category]="A"),0))

    It's all array formulas.

    The structure is the same.

    =COUNT(MATCH(ROW(RANGE),MATCH(DISTINCT_RANGE,DISTINCT_RANGE,0)*(CriteriaRange1=Criteria1)*[CriteriaRange2=Criteria2]),0))

    Otherwise...

    B2 -->=SUM(IF(Table1[Location]=Formulas!A2,1/COUNTIFS(Table1[Location],Formulas!A2,Table1[Name],Table1[Name])))
    C2 --> =SUM(IF((Table1[Location]=Formulas!A2)*(Table1[Category]="B"),1/COUNTIFS(Table1[Location],Formulas!A2,Table1[Category],"B",Table1[Name],Table1[Name])))

    * array formulas.

    https://exceljet.net/formula/count-u...e-with-countif
    Last edited by chief_abound; 06-30-2017 at 10:52 PM.

+ 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: 5
    Last Post: 02-05-2019, 12:03 AM
  2. Formuals to sum distinct values with condition "any" and "all"
    By HeyInKy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-30-2017, 01:04 PM
  3. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  4. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  5. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  6. Replies: 0
    Last Post: 01-09-2013, 06:52 PM
  7. Replies: 3
    Last Post: 02-16-2011, 02:55 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