I have an excel sheet that looks like this (with many more columns and rows of course):
condition a
condition b
condition c
condition d
result (a,b)
result (c,d)
yes
no
yes
no
0
1
no
no
no
yes
0
1
yes
yes
no
no
1
0
...
Now, I only want to separately count the occurrences of either a or b or both are occurring per row, but want to exclude all instances where either a or b (or both) are occurring together with c or d, since I want to count the occurrences where either c or d or both are apperearing separetely. I have toyed around with the idea of using the countifs, but my problem is that I want to count every row separately, so if a and b occur together I only want to count them once, so if I applied countifs to all the colums together, it would count all instances of yes in the a and b column.
For example here in the first row, I would get a 1 for c,d and a 0 for a,b since while there is a yes for a in the first row, there is also one for c.
In the second row, we only have yes for d so it's easy that it's easyily 1 for c,d and 0 for a,b.
And finally in the third row we only have a,b both yes, so it's 1 for a,b since I want to know the occurence per row, and since there is no for both c and d, and so it's 0 for c,d since both are no.
Does anyone know how to solve this in excel? Thank you all for your help
Use AND and OR (COLUMN E):
=--AND(AND(C2<>"yes",D2<>"yes"),OR(A2="yes",B2="yes"))
And (COLUMN F)
=--OR(D2="yes",C2="yes")
If you want to count without the helper columns:
A,B:
=SUMPRODUCT(((C2:C4<>"yes")*(D2:D4<>"yes"))*((A2:A4="yes")+(B2:B4="yes")>0))
C,D:
=SUMPRODUCT(--((C2:C4="yes")+(D2:D4="Yes")>0))
Related
I'm trying to count the following in excel:
I have a number of unique values for X (say 4), each appearing twice (in random order) in the data set. I want to count the number of each combination (regardless of order) of values on a second column Y for each value of X.
Example (here in order):
X Y
1 A
1 D
2 A
2 C
3 B
3 C
4 A
4 D
As output, I need:
n A,D 2
n A,C 1
n B,C 1
n B,D 0
(Let's assume all other combinations don't exist.)
Is this possible without rearranging the data? I don't mind putting in 4 formulas (for each possible combination).
My starting point was akin to this: excel count unique combinations of columns, but I can't quite figure it out and also I know what feels like next to nothing about excel or coding...
To get the count of pairs if the data is not in order, first one needs to get the pairs by X. Create a unique list of X and use this formula:
=CHAR(AGGREGATE(15,6,CODE($B$2:$B$9)/($A$2:$A$9=D2),1))&","&CHAR(AGGREGATE(15,6,CODE($B$2:$B$9)/($A$2:$A$9=D2),2))
Note this only works if the Y is one character like your data.
Then create a unique list of that output and use a standard COUNTIF:
=COUNTIF(E:E,G2)
Or you can use a pivot table on the first helper columns to get the same without the need of getting the unique pairings.
If you use a helper column, you can combine the data into something you can count. Use the formula =IF(A2<>A1,B2,C1&","&B2) in column C. So your data then becomes:
X Y
1 A A
1 D A,D
2 A A
2 C A,C
3 B B
3 C B,C
4 A A
4 D A,D
Then it's a matter of counting up the combinations. Here's a snapshot of my example:
You can use the MMULT function for this purpose, like this (You can insert line breaks with Alt+Enter but you do not have to, it also works if you write it on the same line):
=SUMPRODUCT(
--($B$2:$B$19= LEFT($D2,FIND(",",$D2)-1) ),
MMULT(
--($A$2:$A$19=TRANSPOSE($A$2:$A$19)),
--($B$2:$B$19= MID($D2,FIND(",",$D2)+1,LEN($D2)) )))
You have to enter this as an array formula (After typing, press Ctrl+Shift+Enter, instead of just Enter; you will see the formula inside braces, like this: {=...}).
Here is a screenshot to show what the ranges in the formula mean:
I have two columns that each contain pairs of individuals.
Individual 1 Individual 2
A B
A C
A D
B A
C A
C D
How would I create a count of the number of times an individual has a reciprocal pair i.e. matched with the same partner but in the opposite order? For this example, the output should be:
A: 2
B: 1
C: 1
D: 0
I think this is quite tricky but here are two suggestions
=SUMPRODUCT(COUNTIFS(A$2:A$7,B$2:B$7,B$2:B$7,A$2:A$7,A$2:A$7,C2))
or
=SUM(((A$2:A$7&B$2:B$7)=TRANSPOSE(B$2:B$7&A$2:A$7))*(A$2:A$7=C2))
The second one has to be entered as an array formula using CtrlShiftEnter and I'm assuming that the A's and B's are in A2:A7 and B2:B7 and you can get a list of the four individuals A, B, C and D in C2:C5.
For example, say I have two columns:
ID, Code
1 A
1 B
1 G
2 A
2 F
3 A
3 B
3 C
3 F
4 B
I want to delete any rows for which the ID number is not associated with both A and B somewhere.
So for example all the rows with ID=1 are OK to keep because it is associated with code A and code B.
All rows with ID=2 are to be deleted because it has A, but no B.
All rows with ID=3 are OK because it has both A and B.
All rows with ID=4 are to be deleted because it only has B, no A.
The real file has many rows so I can't do this by hand. Is there a quicker way? I tried using Vlookups somehow but I can't find a way to easily tell which ones to delete.
Using COUNTIFS:
=COUNTIFS(A:A,A1,B:B,"A")+COUNTIFS(A:A,A1,B:B,"B")
Delete all the results that returns 0 or 1 (and keep all the results that give 2).
using 2 temporary helper columns in C & D
1st column = A2 & B2, copied down
2nd column =IF( OR( ISERROR(Vlookup(A2 & "A",C:C,1,FALSE)),ISERROR(Vlookup(A2 & "A",C:C,1,FALSE))),"DeleteMe","SaveMe")
Follow Instructions in column D
Delete Columns C & D
Don't forget to try this on a backup first, so you can enure it works to your satisfaction
I am trying to compare two columns in excel, A and B. Column A contains a complete list of customer numbers. Column B contains an incomplete list of the same customer numbers. So if a customer number is in A, but not in B then output that number to column C.
I'd use the MATCH function in combination with ISNA.
If I have the following table
A B C
1 4
2 3
3 1
4 7
5 2 5
6 6
7
I put in column 'A' the full customer list, and in column B is a random ordered partial list. I then put the function in C1 (and the rest of column C):
=IF(ISNA(MATCH(A1,B:B,0)),A1, "")
Now I see the values '5' and '6' only in column C, because those are the only two numbers that don't appear in column B.
In Cel C1 =IF(ISERROR(VLOOKUP(A1,$B$1:$B$10,1,FALSE)),A1,"")
Adjust for row counts and fill down against column A.
I think you're looking for something like this:
=IF(ISERROR(MATCH(A1,B1,0)),A1,"")
Propegate that formula along your new column and it'll reprint the populated Column A when Column B is a no match.
Reference URL: http://support.microsoft.com/kb/213367
(I believe I read the original question wrong, and am going on the assumption that column A and B are already sorted where the values will line up.)
i am having troubles with the excel function Countif.
I got 2 columns A and B and they should contain (almost) the same entries - which is what i am testing for and i need to know which entries are different. Order does not matter.
columns are actually tickers and look like this
http://pastebin.com/zHdJ5ndp
ok, so i use countif to identify the entries of column B which are not in column A.
Countif(A:A;B1)
Countif(A:A;B2)
...
The result is a column full of zeros, which is just not correct.
other simple tests like
a a 1
b b 1
c c 1
d d 1
e e 1
f f 1
g g 2
g h 0
work just fine!
What am I doing wrong right here?
Thanks in advance!
Are you sure the data in column A and B is the same (no extra space etc)?