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
Last edited by makey; 01-22-2010 at 09:09 AM. Reason: solved
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.
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
Last edited by makey; 01-22-2010 at 02:27 AM. Reason: Mistake in text, re-edit
I've attached a file with the example expanded to three columns and highlighted the cells that would score +ve.
Thanks again
Mike
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.
NBVC, for the first one:
couldn't you use:Code:=SUMPRODUCT((B2:B16>5)+(C2:C16>10),--(D2:D16>20))-SUMPRODUCT(--(B2:B16>5),--(C2:C16>10),--(D2:D16>20))
or am I missing something ?Code:=SUMPRODUCT(--(((B2:B16>5)+(C2:C16>10))>0),--(D2:D16>20))
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 ?
(note change of > operators to >= so as to get the 8 output per highlighted rows in sample file...)Code:=SUMPRODUCT(--(((B2:B16>=5)+(C2:C16>=10)+(D2:D16>=5))>0),--(E2:E16>=20))
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
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
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.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
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.
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.
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.
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:
If we want to SUM contents of C where either A > 5 or B > 10 then we know that:Code:A1: 7 A2: 8 B1: 7 B2: 12 C1: 100 C2: 200
will generate incorrect result of 500 given we end up withCode:=SUMPRODUCT((A1:A2>5)+(B1:B2>10),C1:C2)
ie we're double counting row 2 given both OR conditions return TRUECode:=SUMPRODUCT({1+0,1+1},{100,200})
We can avoid the double count in one SUMPRODUCT by simply validating the SIGN of the OR output:
given this equates toCode:=SUMPRODUCT(--(((A1:A2>5)+(B1:B2>10))>0),C1:C2)
ie the summed OR outputs of 1 and 2 are both greater than 0 - thus 1 multiplier is used in each case.Code:=SUMPRODUCT({1,1},{100,200})
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
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks