+ Reply to Thread
Results 1 to 19 of 19

Count based on group membership

  1. #1
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Count based on group membership

    Hi everyone, I would like to get the number of countries that a given "Name" has Partners in. (See example sheet for an illustration)
    I have the ID of a group in column A. Column B represents Names. Column C gives Info about the country of "Name".
    In column D I would like to get the information how many unique countries a "Name"'s group members are from. This means, not only within a single group, but in total over all groups. This means, that every same Name has the same number of countries in column D.

    Does anyone know how to do this?

    Formula in words:
    "sum of all unique countries in column C, if ID in column A matches any ID of Name in column B"

    Thanks a lot in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Count based on group membership

    Hello

    Hoping that i get correctly your goal we'll use a helper & hidden column(D in the example) to get the results.

    So in D2 and copy down use this.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Hide this column if you want

    Then for getting your results in C2 and copy down.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

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

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  3. #3
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    The Formula for column D gives me a "1" all the time. Accordingly, the formula for column E adds 1 even if I add another partner with from the same country (e.g., if I add a new row for group/ID 1, Name H, Country GER, the count still goes up by one, even though, GER is already included).

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Count based on group membership

    You are welcome....

    ..The Formula for column D gives me a "1" all the time
    NO. This is not correct.

    .. if I add a new row for group/ID 1, Name H, Country GER, the count still goes up by one, even though, GER is already included).
    There is not such a column in your sample sheet.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    Ah, now I see, I am so sorry. The example sheet is wrong for reasons that are a little unclear to me, since I uploaded the file again...

    Now this should all make more sense I guess. Sorry again
    Attached Files Attached Files

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Count based on group membership

    Now we are ok. Can you pls tell me some results that you expect in column C explaing why?

  7. #7
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    I hope, that you are talking about column D now... .
    Please see the attached file for the expected result and the "explanation".
    Basically, it shall start with a name (column B), look up all the IDs, that belong to a given name, then check all the other Names, that share an ID with the given name, and "create" a list of all the countries that the partners of the given name are from. Then it shall "remove all duplicates".
    Attached Files Attached Files

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Count based on group membership

    Unfortunately i am not able to understand the logic behind all this.

    A is groups with Names from GER (ID 1 and 5) and F (ID 3)
    B is in groups only with Names from USA (ID 1 and 5)
    C is in groups with Names from CH (ID 2 and 6), USA (ID 3) and AUS (ID 6)
    Same id could be for different names & countries...

    Same Name can be for different countries & ids..

    Sorry!

  9. #9
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    This is because an ID (i.e. a group) includes several different names. Two Firms can be together in different groups.
    An ID can be for different names and countries, because any ID includes (at least) 2 "names" and these names can be from different countries
    I think you confusion arises from the fact that - based on the focal name (i.e. the name in the respective row) - only the partners in a given group (i.e. names with the same ID) are being looked at.

    A is groups with Names from GER (ID 1 and 5) and F (ID 3)
    B is in groups only with Names from USA (ID 1 and 5)
    To explain with a concrete example (ignore bold for this example):
    here we have two groups, group one has ID 1 and group 2 has ID 5. Both groups consist of A and B. So if I look at A, it is in ID 1 and ID 5. In both IDs, there is only 1 partner, which is from GER. If I look at B, it is the same game, only that the partner is from USA.

    Does this make sense?

    In reality, IDs are Alliance markers, and Names are Firms. Firms are in different alliances. I want to check the international scope of given firms alliances.
    Last edited by Cunner; 05-15-2014 at 07:03 AM.

  10. #10
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Count based on group membership

    Unfortunately not able to understand. Sorry. I have already asked for help here.

    http://www.excelforum.com/the-water-...onwards-6.html

  11. #11
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Count based on group membership

    Here, try this with helper column:

    Difference is that mine result return 1 for AUS while you wrote 2
    Please Login or Register  to view this content.
    But both /4 and 6) has CH & F so that should be 1 unique, as I got. Right?
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    I am sorry, that my explanations seem to be confusing. Whereas I do not understand your formula zbor, I seems as if it might work eventually. So I will try to explain again in (hopefully) simpler terms :p.

    - IDs (column A) are identifiers for groups, i.e. all firms with the same ID are members of the same group (e.g. A and B are in a group; C and D; A and C; D, E and F and so on)
    - Name (column B) are names for different firms
    - Country (column c) is the country in which the firm is located
    - I am always looking from the perspective of a given focal firm (i.e. the firm in the respective row)
    - this firm is a member of some groups (i.e. has some IDs)
    - in these groups, there are - by definition - other firms (i.e. those firms, that share an ID with the focal firm), let's call them alter firms
    - these alter firms are located in different countries
    - I would like to know, how many different countries the alter firms of the focal firm come from, and by this I mean unique countries (e.g., if Firm X is a member in 2 groups, and in both groups the alter firm comes from the same country, this adds just "1")

    Let me know at which step of the argumentation you "lose me" .

    In your example zbor, I believe you used the country as a basis, whereas it should be the name.

  13. #13
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Count based on group membership

    First let me answer of above:
    But both (4 and 6) has CH & F so that should be 1 unique, as I got. Right?
    so I know is mine logic right or not

  14. #14
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Count based on group membership

    This "array formula" in row 2 will give the exact results you expect:

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

    confirm with CTRL+SHIFT+ENTER and copy down - see yellow section in attached
    Attached Files Attached Files
    Audere est facere

  15. #15
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    Quote Originally Posted by zbor View Post
    First let me answer of above: so I know is mine logic right or not
    Yes, if you are looking from the perspective of firm E, you are right, because it doesn't matter that in one case it is firm C and in the other F that is from F(rance). But as E has connections to two different countries (CH and F), the result for E should be "2" (just for IDs 4 and 6).

  16. #16
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    Quote Originally Posted by daddylonglegs View Post
    This "array formula" in row 2 will give the exact results you expect:

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

    confirm with CTRL+SHIFT+ENTER and copy down - see yellow section in attached
    Hey daddylonglegs,
    thanks a lot this seems to work. I do not understand how exactly the formula works (I still don't conceptually understand how to deal with formulas, where arguments are missing...), but I ran some cross checks and changed entries and it seems to work as intended. Thanks a lot everyone!

  17. #17
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    Just a quick question, though:
    the "-1" at the end shall prevent counting a firm's own country, right? If a firm has a partner from the same country as its own country, this isn't counted now, is it?

  18. #18
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Count based on group membership

    Quote Originally Posted by Cunner View Post
    the "-1" at the end shall prevent counting a firm's own country, right?
    That's right, at the moment all countries are counted once each so the -1 just takes out the "home" country

    Quote Originally Posted by Cunner View Post
    If a firm has a partner from the same country as its own country, this isn't counted now, is it?
    Correct - do you want that to be counted? I can probably adjust the formula to work that way.....

  19. #19
    Forum Contributor
    Join Date
    06-24-2009
    Location
    Germany, MG
    MS-Off Ver
    Excel 2010
    Posts
    131

    Re: Count based on group membership

    Sorry, daddylonglegs, for coming back so late to you.
    Thanks for the clarification, I guess I do not need the formula adjustment as based on theory a partner from the same country should not bring any additional "country-specific" knowledge.

+ 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: 1
    Last Post: 02-10-2014, 10:26 PM
  2. Need help: Basic Math / Excel Problem based on Membership Subscriptions
    By lesoies in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-14-2013, 11:09 PM
  3. Need a macro to count certain days Sun, Tues, Thurs for a gym membership sheet
    By barnoonan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2011, 07:32 AM
  4. AD User Group membership Macro
    By Vincent.Eymard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2010, 11:05 PM
  5. Group membership
    By jamex in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 03-09-2006, 09:10 AM

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