+ Reply to Thread
Results 1 to 10 of 10

sum of all possible combinations

  1. #1
    Registered User
    Join Date
    07-24-2012
    Location
    Baltimore
    MS-Off Ver
    Excel for Mac 2011
    Posts
    45

    sum of all possible combinations

    I have a worksheet where the columns represent types of medication and the rows are individual people.

    I need to total how many people have each combination of 12 medications. For example, how many have the combination of med1, med2 and med10; or the combination of med2, med5, med6, med7 and med8; etc. Just examples.

    See attached partial data file (hope it uploaded).

    Thanks for any advice, really appreciate the help!
    Attached Files Attached Files

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: sum of all possible combinations

    If I have interpreted correctly find in the attached a helper table in L1:U10.

    Then this array formula in M2 filled down and across. If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Another interpretation: Also find this formula in K2 filled down with the sum in K1.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Dave

  3. #3
    Registered User
    Join Date
    07-24-2012
    Location
    Baltimore
    MS-Off Ver
    Excel for Mac 2011
    Posts
    45

    Re: sum of all possible combinations

    Thanks Dave. I think the array might work, but I'm struggling to interpret the results.

    Does the helper table give the total for each medication pair or the total for each combination of all 9 medications observed?

    What I'm aiming for is something like:
    1. pi + booster + nnrti only = n persons
    2. pi + booster + insti only = n persons
    3. nnrti + insti only = n persons
    4. sinsti only = n persons
    etc. giving the sum of observations for all distinct combinations of the 9 medications, without regard to order.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: sum of all possible combinations

    Hello mistert,

    I wonder if my answer helps you. First I did an UnPivot of your data to make it into a better (for me) table. Then doing a Pivot Table on sheet2, you can filter which meds you want to see who has them and also their counts. No formulas needed as I'm lazy and did the whole process using built-in Excel tools.

    Unpivot then counts by filter columns.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: sum of all possible combinations

    Quote Originally Posted by mistert View Post
    Thanks Dave. I think the array might work, but I'm struggling to interpret the results.
    1. Does the helper table give the total for each medication pair ...
    2. What I'm aiming for is something like:
    3. 1. pi + booster + nnrti only = n persons
    4. 2. pi + booster + insti only = n persons
    5. 3. nnrti + insti only = n persons
    6. 4. sinsti only = n persons
    etc. giving the sum of observations for all distinct combinations of the 9 medications, without regard to order.
    Yes it gives total for each intersecting pair or combinations. If filters are applied the results will confirm.

    To get a sum of each combination:

    I would have no idea how to lay that out. If I have it right this formula array entered says there are 511 possible combinations. That sounds too conservative to me.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Then you have to count the number of people for those. I would have no ideas how to lay that out or calculate it either.

    OR do a separate table for each patient ... all 99.

    Stay with the thread for a few days. There is a multi-talented, knowledgeable crew here on the forum. Some likely know if there is a practical solution and how to do it.

  6. #6
    Registered User
    Join Date
    07-24-2012
    Location
    Baltimore
    MS-Off Ver
    Excel for Mac 2011
    Posts
    45

    Re: sum of all possible combinations

    Wow, Pivot tables look very useful. Glad to know about them!

    Got me thinking a bit and came up with a partial solution that I bet someone can easily complete.

    On the same worksheet, I used Advanced Filter to copy only unique records to the right of the original data, Table 1. So out of my total 266 patients, there are 53 unique combinations of the 9 medications represented by each row in Table 2.

    This is close. Now what I need is to sum how many observations in Table 1 match each of those 53 unique patterns in Table 2, so I added a sum column but not sure how to count matching row patterns.

    New doc uploaded.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: sum of all possible combinations

    in u3
    =COUNTIFS(B:B,L3,C:C,M3,D:D,N3,E:E,O3,F:F,P3,G:G,Q3,H:H,R3,I:I,S3,J:J,T3)

    the most possible combinations if drug levels are not given is 2^9 =512 but as you can not have a regime with no medication 511 as FlameRetired got to
    Last edited by davsth; 05-30-2018 at 08:10 AM.

  8. #8
    Registered User
    Join Date
    07-24-2012
    Location
    Baltimore
    MS-Off Ver
    Excel for Mac 2011
    Posts
    45

    Re: sum of all possible combinations

    Quote Originally Posted by davsth View Post
    in u3
    =COUNTIFS(B:B,L3,C:C,M3,D:D,N3,E:E,O3,F:F,P3,G:G,Q3,H:H,R3,I:I,S3,J:J,T3)

    the most possible combinations if drug levels are not given is 2^9 =512 but as you can not have a regime with no medication 511 as FlameRetired got to
    That did! Thanks to everyone for the help!!!

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: sum of all possible combinations

    Hi misert,

    Is this workbook the correct answer?
    Do the totals add up?

    CountifS Answer.xlsx

  10. #10
    Registered User
    Join Date
    07-24-2012
    Location
    Baltimore
    MS-Off Ver
    Excel for Mac 2011
    Posts
    45

    Re: sum of all possible combinations

    Yep, that's exactly what I got using your formula. I double checked about 4 of the combinations and the totals are correct. Thanks man!

+ 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. ODD and Even Combinations
    By Prit50 in forum Excel General
    Replies: 4
    Last Post: 05-29-2017, 02:59 PM
  2. Combinations
    By zak.horrocks in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-23-2016, 07:39 AM
  3. Finding possible combinations & listing the wanted combinations
    By Zoke in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 07-16-2012, 03:41 PM
  4. Combinations
    By tazpyro1 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 05-09-2012, 01:44 PM
  5. Combinations
    By mthurman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2011, 03:48 PM
  6. Excel 2007 : Combinations
    By freehawk in forum Excel General
    Replies: 1
    Last Post: 12-18-2010, 12:05 PM
  7. Combinations
    By osprey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 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