+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    01-21-2010
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Question Summing the data from two sets?

    Hi all,

    I’m just wondering if anyone can offer any assistance out there, with a query I have regarding my excel predicament.

    I’m trying to get the total number of participants in two different sets, with selection criteria attached to both (I’ve attached an excel file, as the example with those scoring +ve highlighted in yellow). The first set A (b1:b15) I want to select all values above 5, and the second B (c1:c15) set above 10. There other provisor, is that the A and B are further split into two groups (one above and one below 20).

    In summary, I need to count all the A>5, B>10 (And both have to be above 20 in column D), but not to double count the ones that have Both A>5 and B>10. I don’t want any duplicates to be counted, so summing the total of A and adding it to B won’t work. In essence it’s an attempt to use the A Union B function that you’d observe when using venn diagrams.

    Is there a simple way/formula of doing this? The idea is that I can then expand it onto three and four parameters per participant. Many thanks for taking the time to read this, and I would really appreciate any guidance!

    Mike
    Attached Files Attached Files
    Last edited by makey; 01-22-2010 at 09:09 AM. Reason: solved

  2. #2
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Summing the data from two sets?

    Does this work?

    =SUMPRODUCT((B2:B16>5)+(C2:C16>10),--(D2:D16>20))-SUMPRODUCT(--(B2:B16>5),--(C2:C16>10),--(D2:D16>20))
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  3. #3
    Forum Moderator pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,141

    Re: Summing the data from two sets?

    Hi makey
    possibly
    =SUMPRODUCT(--($B$2:$B$16>5)*--($C$2:$C$16>10)*--(D$2:D$16>20))
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    JBeaucaires Excel Files

    VBA for smarties - snb

  4. #4
    Registered User
    Join Date
    01-21-2010
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Summing the data from two sets?

    Quote Originally Posted by NBVC View Post
    Does this work?

    =SUMPRODUCT((B2:B16>5)+(C2:C16>10),--(D2:D16>20))-SUMPRODUCT(--(B2:B16>5),--(C2:C16>10),--(D2:D16>20))
    Hi,

    Thanks for both the quick replys,

    NVBC, you one seems to work quite well!
    Just a quick question, if I want to expand that to other columns i.e. if i insert ones into D how would I adapt that to work?

    Assuming that D was >5


    Thanks again

    Mike
    Last edited by makey; 01-22-2010 at 02:27 AM. Reason: Mistake in text, re-edit

  5. #5
    Registered User
    Join Date
    01-21-2010
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Summing the data from two sets?

    I've attached a file with the example expanded to three columns and highlighted the cells that would score +ve.

    Thanks again

    Mike
    Attached Files Attached Files

  6. #6
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Summing the data from two sets?

    Test this one out:

    Code:
    =SUMPRODUCT((B2:B16>5)+(C2:C16>10)+(D2:D16>10),--(E2:E16>20))-SUMPRODUCT(--(B2:B16>5),--(C2:C16>10),--(E2:E16>20))-SUMPRODUCT(--(B2:B16>5),--(D2:D16>10),--(E2:E16>20))-SUMPRODUCT(--(C2:C16>10),--(D2:D16>10),--(E2:E16>20))
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  7. #7
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Summing the data from two sets?

    NBVC, for the first one:

    Code:
    =SUMPRODUCT((B2:B16>5)+(C2:C16>10),--(D2:D16>20))-SUMPRODUCT(--(B2:B16>5),--(C2:C16>10),--(D2:D16>20))
    couldn't you use:

    Code:
    =SUMPRODUCT(--(((B2:B16>5)+(C2:C16>10))>0),--(D2:D16>20))
    or am I missing something ?

    If the above assumption is correct ...

    I suspect you could push into an OR like the above (ie test SIGN of OR output and use that as multiplier) to the next example though I confess I don't follow 100% - should the result be 8 ?

    Code:
    =SUMPRODUCT(--(((B2:B16>=5)+(C2:C16>=10)+(D2:D16>=5))>0),--(E2:E16>=20))
    (note change of > operators to >= so as to get the 8 output per highlighted rows in sample file...)

    apologies if I'm barking up the wrong tree... apologies also for late edits
    Last edited by DonkeyOte; 01-22-2010 at 09:05 AM. Reason: missing set of brackets

  8. #8
    Registered User
    Join Date
    01-21-2010
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Summing the data from two sets?

    Quote Originally Posted by NBVC View Post
    Test this one out:

    Code:
    =SUMPRODUCT((B2:B16>5)+(C2:C16>10)+(D2:D16>10),--(E2:E16>20))-SUMPRODUCT(--(B2:B16>5),--(C2:C16>10),--(E2:E16>20))-SUMPRODUCT(--(B2:B16>5),--(D2:D16>10),--(E2:E16>20))-SUMPRODUCT(--(C2:C16>10),--(D2:D16>10),--(E2:E16>20))
    Thanks again for both the replys, much appreciated

    I think you've cracked it NBVC, I ran that through an it's working a treat.

    Many thanks again

    Mike

  9. #9
    Registered User
    Join Date
    01-21-2010
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Summing the data from two sets?

    Quote Originally Posted by DonkeyOte View Post
    NBVC, for the first one:

    Code:
    =SUMPRODUCT((B2:B16>5)+(C2:C16>10),--(D2:D16>20))-SUMPRODUCT(--(B2:B16>5),--(C2:C16>10),--(D2:D16>20))
    couldn't you use:

    Code:
    =SUMPRODUCT(--(((B2:B16>5)+(C2:C16>10))>0),--(D2:D16>20))
    or am I missing something ?

    If the above assumption is correct ...

    I suspect you could push into an OR like the above (ie test SIGN of OR output and use that as multiplier) to the next example though I confess I don't follow 100% - should the result be 8 ?

    Code:
    =SUMPRODUCT(--(((B2:B16>=5)+(C2:C16>=10)+(D2:D16>=5))>0),--(E2:E16>=20))
    (note change of > operators to >= so as to get the 8 output per highlighted rows in sample file...)

    apologies if I'm barking up the wrong tree...
    Thanks for the input as well. The final answer should have been 6. It's essentially a union function A U B U C which I was looking for.

  10. #10
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Summing the data from two sets?

    The first formula I suggested would give 6 per first sample file.

    The second formula would generate 8 based on 2nd sample file, if expected result was 6 for that file also you need simply revert the >= operators back to > ... the file was a tad confusing.

  11. #11
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Summing the data from two sets?

    You are welcome Makey. Glad it worked...

    DonkeyOte, as you probably know by now, I tend to be more brute force (probably why I am not that great in VBA programming)... so my formulas can sometimes be longer than other solutions that might also work (and possibly be more efficient)... I don't have speed calculators to see which is faster... as you know, shorter is not always more efficient, although, in this case, I have a funny feeling yours may be more efficient...

    ... but for what Makey seems to be doing, it doesn't seem that he/she will see any real performance issues....

    ... if you have alternative suggestions, please be my guest and provide them... somebody out there could find them useful.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  12. #12
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Summing the data from two sets?

    Quote Originally Posted by DonkeyOte View Post
    The first formula I suggested would give 6 per first sample file.

    The second formula would generate 8 based on 2nd sample file, if expected result was 6 for that file also you need simply revert the >= operators back to > ... the file was a tad confusing.
    Using my formula I got 6 in the sample file...
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  13. #13
    Forum Moderator NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003, 2007, 2010
    Posts
    31,163

    Re: Summing the data from two sets?

    Now we are just walking over each other.....
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  14. #14
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Summing the data from two sets?

    I was simply trying to illustrate how to avoid double counting in one singular SUMPRODUCT function by virtue of testing the SIGN of the output of the OR's.

    Using a much simplified version to illustrate:

    Code:
    A1: 7
    A2: 8
    
    B1: 7
    B2: 12
    
    C1: 100
    C2: 200
    If we want to SUM contents of C where either A > 5 or B > 10 then we know that:

    Code:
    =SUMPRODUCT((A1:A2>5)+(B1:B2>10),C1:C2)
    will generate incorrect result of 500 given we end up with

    Code:
    =SUMPRODUCT({1+0,1+1},{100,200})
    ie we're double counting row 2 given both OR conditions return TRUE


    We can avoid the double count in one SUMPRODUCT by simply validating the SIGN of the OR output:

    Code:
    =SUMPRODUCT(--(((A1:A2>5)+(B1:B2>10))>0),C1:C2)
    given this equates to

    Code:
    =SUMPRODUCT({1,1},{100,200})
    ie the summed OR outputs of 1 and 2 are both greater than 0 - thus 1 multiplier is used in each case.

    It follows that we can add as many OR conditions as we want prior to the >0 test without affecting result.

    (you could use SIGN rather than --(...>0) but Aladin has argued in the past that that approach would be a little slower given the additional function call)
    Last edited by DonkeyOte; 01-22-2010 at 09:25 AM. Reason: added note re: SIGN

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0