how do you count using if and sumproduct - excel

I have a database of people who may or may not have multiple entries and I'd like to know how to count the total number of people who are male who meet another category using a formula. I current use the
=SUMPRODUCT((MelanomaEth="U")/COUNTIF(MelMRN,MelMRN&"")))
formula to count the number of unique entries with a "U" in the MelanomaEth column. However, I'd like to go further and determine how many of these U's are males and females.
I tried to use:
=IF(MelSex="M",SUMPRODUCT((MelanomaEth="U")/COUNTIF(MelMRN,MelMRN&"")))
but it gives me the incorrect number.
Here is an "dummy" sheet:
MRN Date Sex Ethnicity
A 8/1/2013 M U
B 8/2/2013 F N
C 8/2/2013 F N
A 9/2/2013 M U
A 9/3/2013 M U
C 8/31/2013 F N
B 8/15/2013 F N
D 10/5/2013 M U
If I wanted to know the number of unique names who are M and U, I should get 2. The number of names who are F and U should be 0, FN should be 2, and 0 MN.
Any suggestions would be appreciated.
Thanks!

Try this:
=SUMPRODUCT(((MelanomaEth="U")/COUNTIF(MelMRN,MelMRN&""))*((MelSex="M")/COUNTIF(MelMRN,MelMRN&""))
What your looking for is a sumproduct with multiple criteria. Usually the format is something like this:
= SUMPRODUCT((RANGE CONDITION)*(RANGE2 CONDITION2))
= SUMPRODUCT(( D1:E5 > 1 )*( D1:E5 < 10 ))
If a condition is false, then the whole statement is false and wont be counted.
Since I'm not sure what your names represent I can't be sure the code above will work for you.

I got it!
It was simpler than I thought. For those who need this,
=SUMPRODUCT((MelanomaEth="U")*(MelSex="F")/COUNTIF(MelMRN,MelMRN&"")))
This gives the unique number of MRN who meet the criteria F and U.

=SUMPRODUCT((O10:O21<>"")/COUNTIF($O$10:$O$21,O10:O21&"")) counts unique cells in the range

Related

How to calculate similarity percentage between multiple strings in Python?

I know this question has been asked several times but I could not find the satisfying answer, so I attempt to try to ask one more time. I have 6 string lists (A-F), which contains codename.
A=('com','kaw','has','lot','sfa','alm','wah')
B=('bac','blm','cba','com','dol','has','kaw','lis','lot','lsv','mco','mil','oby','sfa','wah')
C=('fri','com','dol','emo','has','kaw','lot','mco','moo','pob','rag','sfa','skj','wah')
D=('com','dol','kaw','lot','lsv','mil','sfa')
E=('com','has','kaw','lot','mco','pob','rru','sfa','wah')
F='fri','bet','bip','blt','brz','cnt','dol','kaw','lec','mas','rnj','rru','sfa','skj','swo','wah','yft')
I want to calculate the similarity percentage (SP) between A and others. The result should be a table, where each List contains SP to other list.
Like this
A B C D E F
A
B
C
D
E
F
Thank you in advance!

Using Google Sheets (or MS Excel) need formula to sum columns to a third column with conditions

I am developing a hockey scoresheet for my son's youth team. I need to figure out how to sum goals by period. I have up to 16 goals per game. Each is identified by period and some other data not relevant to this question (Jersey, assists, etc.). Once the data is entered, I want to show total goals by period. I need help with this part.
Specifically, I need a formula which will look at column A (Period) and if the condition is met add the value in column B (which will typically, but not always be 1) to column G (Period 1 Total). Also, do the same for columns C & D and E & F. Always adding the value to column G.
Columns A,C,D are the period the goal is scored. Columns B,D,F is the point value added. (In reality, my spreadsheet does this with 16 possible goals, but for illustrative purposes, I'm only showing 3 possible goals.)
So, Column G will have a formula that says,
If A = 1 then add B to G
If C = 1 then add D to G
If E = 1 then add F to G
G could have a result of 0 to 3 depending how many goals are scored.
My belief is that additional Columns H and I will represent periods 2 and 3. These two columns will use the same formula as G, except filtering for "2" or "3" in columns A,C,D.
I hope the examples help make sense of the request. Thank you.
Example 1: 3 goals scored in first period
---Goal 1------------Goal 2-----------Goal 3-------Period 1
Period Goal----Period Goal----Period Goal----Goals
--A--------B--------C-------D---------E-------F---------G
--1--------1---------1-------1----------1-------1----------3
Example 1: 2 goals scored in first period
---Goal 1------------Goal 2-----------Goal 3-------Period 1
Period Goal----Period Goal----Period Goal----Goals
--A--------B--------C-------D---------E-------F---------G
--1--------1---------1-------1---------- ------- ----------2
Example 3: 2 goals scored in first period 1 goal scored in period 2
---Goal 1------------Goal 2-----------Goal 3-------Period 1
Period Goal----Period Goal----Period Goal----Goals
--A--------B--------C-------D---------E-------F---------G
--1--------1---------1-------1----------2-------1----------2
You can use SUMIFS()
=SUMIFS(B3:F3,$B$2:$F$2,"Goal",A3:E3,1)
Turns out it was much easier than I thought. I was overthinking things.
=SUM(IF(A1=1,B1),IF(C1=1,D1),IF(E1=1,D1))
Thanks for viewing. I hope this helps someone else out.

Finding top 5% in Excel

I have a list of data in Excel, with values attributed to the different samples. I would like to subset the top 5% from all my data. How can I do this in Excel?
sample value
a 0.6001437980
b 0.0983224370
c 0.0493093160
d 0.0427906350
e 0.0413478790
f 0.0299204810
g 0.0259600660
h 0.0215505810
i 0.0167398000
j 0.0131496290
k 0.0105364240
l 0.0082647980
m 0.0068507060
n 0.0065234580
o 0.0050233730
In cell C2, enter
=B2>=PERCENTILE($B$2:$B$63,0.95)
you can then copy this to C3:C63.
Column C now shows TRUE only for those rows with a B value in the top 5%.
Additionally you may like to apply a filter.
You can specifie rang of your data and then color it with very little effort.
Here is an example, where you can color top N records:
Hope it helps :)

Index/Match with Min (or equivalent)

I'm trying to return a value based on the MIN() in a range. Here's a screenshot, but here's the data:
Category Types pts Policeman Hero
Jurisdiction City -10 x
State 0
Country 20 x
Vehicle Car -2 x
Bus 20
Unicycle 20 x
Sidekick No Sidekick -20 x
One 5
Multiple 10 x
Powers None -30 x
Super 2 x
Kenny 30
My goal is for each "person" (Policeman and Hero), look in their column, and return the value from column B, where there's an X by the "minimum" value.
In other words, for "Policeman", the min. value with an 'X' is "No Sidekick", so I want my Index/Match to return that. For "Hero", the minimum value with an "X" is "None" (under "Powers").
I've tried:
=Index(B2:B13,Match(Index(Min(C2:C13),Match("x",D2:D13,0))&"x",C2:C13&D2:D13,0)) but it doesn't work.
I've also tried
=Index(B2:B13,Min(If(D2:D13="x"),Row(D2:D13)-1))
I can see the formula in my mind, just can't figure out where I'm going wrong. Thanks for any ideas/help.
(I don't have to use Index/Match, so if there's another way (Sumproduct() perhaps?), I'm open to it!)
The following will do it(Untested):
=INDEX($B$2:$B$13,MATCH(1,INDEX((D$2:D$13="x")*($C$2:$C$13=AGGREGATE(15,6,$C$2:$C$13/(D$2:D$13="x"),1)),),0))
Only because it is Bruce.
I merged the column D and E and so forth, and yes I know I did the cardinal sin in merging but hey, I figure you can do what you want. I am just showing a concept:
In D14:
=AGGREGATE(15,6,$C$2:$C$13/(D$2:D$13="x"),ROW(1:1))
Then in E14:
=INDEX($B$2:$B$13,AGGREGATE(15,6,(ROW($C$2:$C$13)-1)/((D$2:D$13="x")*($C$2:$C$13=D14)),COUNTIF(D$14:D14,D14)))
Then copy down and over
One answer using index/match would be
=INDEX($A$2:$A$15,MATCH(MIN(IF($C$2:$C$15="x",$B$2:$B$15,9999)),IF($C$2:$C$15="x",$B$2:$B$15,""),0))
columns are wrong since I used my own data but the concept works.

How do I define multiple formulas in excel?

I have no idea if this is the right place to ask this, but I am really struggling with excel. I am trying to define two formulas in excel, and then make a 2 variable data table to run these formulas through.
My formulas are:
Q = SQRT( 2*U*A ) / SQRT(h) , and if you use that best quantity Q then the acquisition and holding costs yield a corresponding TOTAL COST = SQRT( 2*U*A ) * SQRT(h).
We are then given a range of values for U and h, with A constant.
How do I define these equations in excel?
Here's a start, type this in (without the A B C... and 1,2,3... at top):
A B C D E
1 A U h Q Total
2 123 1 100 =SQRT(2*B2*$A$2)/SQRT(C2) =SQRT(2*B2*$A$2)*SQRT(C2)
3 2 200 =SQRT(2*B3*$A$2)/SQRT(C3) =SQRT(2*B3*$A$2)*SQRT(C3)
4 3 300 =SQRT(2*B4*$A$2)/SQRT(C4) =SQRT(2*B4*$A$2)*SQRT(C4)
Also, have a look at https://faculty.fuqua.duke.edu/~pecklund/ExcelReview/2001_Documents/2001XLGettingStarted.pdf

Resources