Excel: Count of reciprocal pairs in two columns - excel

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.

Related

Getting the max of a column based on criteria in another column

I have some data like:
Group
Alpha
Numeric (Sometimes)
1
A
Z
1
B
X
1
C
Y
2
B
Z
2
A
X
2
C
Y
A, B, and C repeat in that not necessarily in that pattern but always in groups together, while the numeric column is often numeric data that varies or text. How can I get the max numeric value for a group for just A and B using a repeatable formula (or a lambda function)? I have tried using vlookup for A and B in the range composing a group and passing the numeric column to MAX() but when the numeric column has text, MAX() and MIN() fail (even though it supposedly ignores text). Any ideas on how to get it to return correctly?

Using excel to count with conditions

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))

EXCEL: count combinations for unique values

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:

Keep on summing corresponding cell and compare with first column for summing up first column based on comparision in excel

Consider the following data setup:
_A_ _B_ _C_
1 1
2 1 1
3 3
Such that a formula would return the following results for columns B and C respectively:
_A_ _B_ _C_
4 2
Now I want to sum column A if A-(B+C) is equal to 0.
so for above example sum would be 1+3 = 4 on column B, since row 1 and 3 satisfy 1-1=0 first row, 3-3=0 third row. so A value on 1st and 2nd row is 1+3=4. Row 2nd doesn't satisfy 2-1=1 not 0 so ignore.
on column C, B+C in second row 2-(1+1) = 0 ,So it would be sum 2 in that column C, ignoring first and third row since it already has been counted on column B.
columns continue like D E....
So sum up from B to current column..so if i am in column B it will sum up till B.If in C B+C....If in D B+C+D etc and then compare with column A
Insufficient rep to comment, this is at least a partial answer and perhaps full.
I think you're looking for this to happen in some lower row in B:
=SUMPRODUCT(--(A1:A3=B1:B3),A1:A3)
And this in C:
=SUMPRODUCT(--(A1:A3-(B1:B3+C1:C3)=0),A1:A3)
Although as EEM points out all the sample rows satisfy this condition so you get "6" instead of "2"

Compare two Excel columns, output cells in A that do not appear in B

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

Resources