Compare 2 excel columns if their corresponding ID's match - excel

I have 4 excel columns. I want to compare if 2 columns (Type) match if their corresponding IDs match. ID is unique.
Example
ID Type ID Type
1 A 2 B
2 B 3 C
3 C 4 A
4 D 6 F
5 A
Output desired is result column if match found or no.
Which function should I use. I tried vlookup but I don't know how to check only their IDs match.

If these are in columns A through D you could use in Column E:
=if(vlookup(C1, A:B, 2, false)=D1, "Matches", "Doesn't Match")
This will look up the C1 value into the A:B list and see if the corresponding Type matches when the ID's match.

Related

Checking if pair of values exists in pair of columns?

I am attempting to find in Excel whether a unique pair of values exists across two columns in a separate spreadsheet. For example:
Array 1
1 - A
2 - B
3 - A
4 - C
Array 2
1 D
2 E
2 B
3 C
I would like the column next to 2, B to return "TRUE", and all other columns to return "FALSE", as 2B exists in Array 2 but none of the other pairds do.
I've tried surfing Stack Overflow for this problem as I felt it would be a very common lookup but surprisingly have had no luck so far. VLookups have given some results but they stop at the first pair. For example let's say we had Array 3:
Array 2
1 D
2 E
2 B
4 C
Now both 2B and 4C in Array 1 should return trues.
Formula in C1:
=COUNTIFS(D:D,A1,E:E,B1)>0
Array one in Column A
Array two in Column B
Paste this XLookup in Column C1, then drag formula down to C4. The corresponding values that match will be listed next to the values from Column A if they exist in Column B.
=XLOOKUP(A1,B$1:B$4,B$1:B$4,"",0,1)

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"

Excel vlookup expansion

I currently have an excel worksheet with three columns
id annotation person_id
1 yes 1
1 no 2
1 yes 3
I'm trying to reformat this on another worksheet into a table that looks like:
id 1 2 3
1 yes no yes
I'm using this
vlookup: =VLOOKUP(A2,sheet2!$F$1:$G$10,2,FALSE)
where a2 is the id and f$1:g$10 is the range of data for that particular person.
At the moment I'm doing this per person and its tedious - there's thousands of people. I need a way to incorporate the person_id into my vlookup so that, if the person_id in the column header matches the person_id in sheet 2 and both ids match, then insert the annotation.
This appears to be a good candidate for an INDEX-MATCH formula, with a multi-condition MATCH() formula to account for both ID criteria. The formula below places the raw data are in A1:C4 and the reformatted data in E1:H2, so you will need to change the references:
In cell F2, I've entered {=INDEX($A$1:$C$4, MATCH(1, ($A$1:$A$4=$E2)*($C$1:$C$4=F$1), 0), 2)}, which yields
[A] [B] [C] [D] [E] [F] [G] [H]
[1] id annotation person_id ID 1 2 3
[2] 1 yes 1 1 yes no yes
[3] 1 no 2
[4] 1 yes 3
The relative references on $E2 and F$1 allow the filling of the formula across rows and columns.
To explain the formula a bit:
In the INDEX() formula, the first argument $A$1:$C$4 is the raw data "table" (array).
The second argument searches for the row where the value ($A$1:$A$4=$E2)*($C$1:$C$4=F$1) is exactly (given by the third argument, 0) equal to 1.
($A$1:$A$4=$E2)*($C$1:$C$4=F$1) is the multiplication of two TRUE/FALSE statements, which is equal to 1 when the main ID in col A is equal to the ID value in E2, and the person ID in col C is equal to the column header in F1.
The final argument, 2, is the column in the data table from which to look up the result.
You may want to consider using another MATCH() formula to dynamically identify the look-up column based on the column header; e.g., instead of 2, use MATCH("annotation", $A$1:$C$1, 0).
Important notes:
The formula needs to be entered as an array formula using Ctrl+Shift+Enter.
This method assumes the combinations of id & person_id are unique.
Also, note that this formula is clearer with named ranges: e.g. (using the suggested second MATCH() function instead of 2), {=INDEX(RawData, MATCH(1, (ID=$E2)*(PersonID=F$1), 0), MATCH("annotation", Headers, 0)}.
You could do like this
First create a new column on the first table =B2&D2
A B C D
1| id annotation person_id
2| 11 1 yes 1
3| 12 1 no 2
4| 13 1 yes 3
And then on the second table use a formula like this
=VLOOKUP(B16&C15;A2:C4;3;FALSE)
B C D F
14 1 2 3
15 1 yes no yes
16 2

Merge unique values if another cell matches

Merge all unique values if another cell matches. I already know how to merge cells but now some information is double. So what I would like to achieve is the following:
if column A has the same name, then all values given in column B for
that name must be given only ONCE in a new column.
My data has a row names and a row mode, for example (Row 1 is header)
A B
2 Brenda a
3 Brenda a
4 Joey a
5 Joey b
So I want:
E
2 a
3
4 a,b
5
I already did merge the modes in column 3:
=IF(A1<>A2;B2;C1&","&B2)
So I get in this example:
C
2 a
3 a,a
4 a
5 a,b
Then, I already did that only the first record get the additional modes in column 4:
=IF(A1=A2;"";INDEX(Sheet1!$C:$C;COUNTIF(Sheet1!$A:$A;$A2)+MATCH($A2;Sheet1!$A:$A;0) -1))
So I get in this example
D
2 a,a
3
4 a,b
5
Now I need a column that only uniques values are given for each name. So in this example:
E
2 a
3
4 a,b
5
If I am understanding how your data is structured, try this:
Add a new column, say column G for ease of explanation, that concatenates the name and mode in each row. So, cell G2="Brendaa", G3="Brendaa", G4="Joeya", G5="Joeyb", etc.
In your merge step you will test whether the current value in the cell for this column matches any previous values in the column: If no, you do the merge; if yes, you don't.
Your merge formula would change to something like the following:
=IF(A1<>A2,B2,IF(ISERROR(VLOOKUP(G2,G$1:G1,1,0)),C1&","&B2,""))
Then you would the next step as before.

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