+ Reply to Thread
Results 1 to 12 of 12

count distinct values and return required group categories

  1. #1
    Registered User
    Join Date
    07-11-2016
    Location
    usa
    MS-Off Ver
    2016
    Posts
    78

    count distinct values and return required group categories

    Hi,

    I want to write a formula which will give me a sum of the count of distinct values in Column B (User). Based on the value from Col B i want the desired output in Column C (Output). If Distinct sum is >3, then output = "Large". If distinct sum = 3, then output = "Medium" and if Distinct sum < 3, then output = "Small". In my example, the distinct count of users for Boston = 3, for Chicago = 2, LA=2 and Denver = 5. Hope you can assist me with the formula
    Attached Files Attached Files

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: count distinct values and return required group categories

    Not sure how you get your answers (you have a count of 1 as Large and a count of 4 as Small?), but try either of these...

    =INDEX({"small","medium","large"},MIN(3,COUNTIF($B$2:$B$18,B2)))
    or
    =IF(COUNTIF($B$2:$B$18,B2)<3,"small",IF(COUNTIF($B$2:$B$18,B2)=3,"medium","large"))
    copied down
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    07-11-2016
    Location
    usa
    MS-Off Ver
    2016
    Posts
    78

    Re: count distinct values and return required group categories

    Hi FDibbins,

    Thanks for getting back to me. Let me explain my logic again as your solution is not getting me the desired end result. So Boston has Users listed as A1,A1,A2 and A3. So the distinct count of users is only 3 which is A1,A2,A3.
    Similarly for Denver, there are 5 users, D1,D2,D3, D4,D5. So the distinct count of Denver users is 5 (which is D1-D5). Now using this count of distinct users we come up with the categories of small , medium and large.
    Hope this clarified things, if not please let me know.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,821

    Re: count distinct values and return required group categories

    Are you still using Excel 2010? If not, please update your profile. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    07-11-2016
    Location
    usa
    MS-Off Ver
    2016
    Posts
    78

    Re: count distinct values and return required group categories

    Hi AliGW,

    Thanks for bringing this to my attention. I have updated my excel version now to 2016. My apologies.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: count distinct values and return required group categories

    In D2

    =IF(COUNTIF($A$2:$A2,$A2)=1,SUMPRODUCT(1/COUNTIF(OFFSET($A2,,1,COUNTIF($A:$A,$A2)),OFFSET($A2,,1,COUNTIF($A:$A,$A2)))),"")

    in E2

    =IF(COUNTIF($A$2:$A2,$A2)=1,IF($D2<3, "Small",IF($D2=3,"Medium","Large")),"")
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-11-2016
    Location
    usa
    MS-Off Ver
    2016
    Posts
    78

    Re: count distinct values and return required group categories

    Hello John,

    You are almost there. How do we get the values to populate under the blank cells? Like Cell D3, D4, D5 should have the same value as cell D2 which is 3 instead of blank cells. Similarly for other cells below. Would that be possible to incorporate?

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: count distinct values and return required group categories

    =IF(COUNTIF($A$2:$A2,$A2)=1,SUMPRODUCT(1/COUNTIF(OFFSET($A2,,1,COUNTIF(A:A,A2)),OFFSET($A2,,1,COUNTIF(A:A,A2)))),D1)

    =IF(D2<3,"Small",IF(D2=3,"Medium","Large"))

  9. #9
    Registered User
    Join Date
    07-11-2016
    Location
    usa
    MS-Off Ver
    2016
    Posts
    78

    Re: count distinct values and return required group categories

    wow...that worked like a charm John. I had to move around the columns a little bit and the formula stopped working. Could you tell me what minor adjustment i need to make in the formula of the newly attached file? Col P and Col Q is where i listed your formulas which will need a slight tweaking.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: count distinct values and return required group categories

    try

    =IF(COUNTIF($A$2:$A2,$A2)=1,SUMPRODUCT(1/COUNTIF(OFFSET($A2,,8,COUNTIF(A:A,A2)),OFFSET($A2,,8,COUNTIF(A:A,A2)))),P1)

    The BOLD number is the column offset from column A where the Use is (now in I) which 8 columns along from A
    Last edited by JohnTopley; 09-09-2021 at 10:28 AM.

  11. #11
    Registered User
    Join Date
    07-11-2016
    Location
    usa
    MS-Off Ver
    2016
    Posts
    78

    Re: count distinct values and return required group categories

    Thank you so very much John. The explanations really helped and the solution will save me a ton of time. I really appreciate your help...God bless !

  12. #12
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: count distinct values and return required group categories

    You're welcome and thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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 distinct values and categories
    By poaxxafllad in forum Excel General
    Replies: 8
    Last Post: 11-24-2020, 08:21 PM
  2. Tally number wise required sum of hours,amounts,count of strength as per categories.
    By Mohammad Munawar in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-01-2020, 07:13 AM
  3. Count of Values (Rows) of Most Recent Consecutive Streak (2+ Distinct Values)
    By ExcelForum88 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-13-2016, 12:26 PM
  4. [SOLVED] Help Required: Assign Values to Categories
    By Aerodynamix in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 12-08-2015, 01:09 PM
  5. [SOLVED] Unable to assign values to categories - Rules based formula help required
    By Aerodynamix in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-21-2015, 12:40 PM
  6. Count Distinct Values
    By trevordsmith in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-02-2014, 09:21 PM
  7. [SOLVED] Count Distinct Values by Group Using Pivot Table (NM)
    By MCP in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-11-2005, 06: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