Excel match two columns and output third - excel

I would like a formula that iterates over the first and second column and returns the third column if
Column 1 = "a" AND
Column 2 = "d"
the formula should return the value in the third column of the corresponding row, in this case
it would be 3. otherwise, it should output 0.

You can use the formula:
=IF(MATCH("foo",A1:A4,0)=MATCH("bar",B1:B4,0),INDEX(C1:C4,MATCH("bar",B1:B4,0)),0)
of course you can change the "foo" and "bar" text within the formula to use another cell reference. Anyways, this should get you started at least.
Edit:
If "bar" is only found once in column B Then you can use
=IF(INDIRECT("A"&MATCH("bar",B1:B4,0))="foo",INDEX(C1:C4,MATCH("bar",B1:B4,0)),0)
One last thing, for both cases, if "bar" is never found in column B it will return #N/A if you want to change that you can wrap the whole thing in an IFERROR() statement and return your 0 .

I think, you are looking for something like this, assuming column 1 is A1 and column 2 is B1:
=IF(AND(A1="foo",B1="bar"),"bo",0)
If you have multiple values that you need column 3 to be you can do an embedded if statement like for your second row:
=IF(AND(A1="foo",B1="bar"),"bo",IF(AND(A1="fui",B1 = "bas"),"bis",0))
Basically where you would have 0, you write the next if statement and it will run through, until it hits true or defaults to 0.

I do not think Excel has this feature.
If you are looking up numbers, there is a work around though:
=IF(COUNTIFS($A$1:$A$4,"a",$B$1:$B$4,"d") = 1, SUMIFS($C$1:$C$4,$A$1:$A$4,"a",$B$1:$B$4,"d"), "ERR")
This will yield the number if there is exactly one match, and "ERR" if there are none or many matches. If you try to use it to look up text, it will return 0.

is that what you need ?
=IF(AND(A1="foo",B1="boo"),"boo",0)

Related

Excel Vlookup Formula Troubleshooting

I'm goofing a bit on the syntax here.
But in most basic terms, if sheet 'CT', column B has a corresponding lookup value in column B of sheet 'CT WKSHT' AND column K of 'CT WKSHT' is N/A (this cell is a formula that will not always have a value) then I want to populate a 1 else a 0.
The formula below is sort of conceptually what I'm trying to do, but I'm not doing this right clearly.
Please help if you can, as I get stuck when I think about getting vlookups to have additional conditions on them.
=IFERROR(VLOOKUP(CT!B4,'CT WKSHT'!B8:K8,10,FALSE),1,"")
Why are you even working with VLookup()? If I read your formula, it reads like:
Look for a value in column B and if you find it, return the value of column K.
If the lookup did not work, then show 1
If the lookup did work, then show and empty string
Why do you want to return value of column K if you overwrite it with an empty string anyway?
I would advise you the following formula:
=IFERROR(VLOOKUP(CT!B4,'CT WKSHT'!B8:K8,10,FALSE),1)
Is this better?
Also, you are looking for that value just on row 8, why not for the whole range:
=IFERROR(VLOOKUP(CT!B4,'CT WKSHT'!B:K,10,FALSE),1
This should do it. It combines a normal IF statement with ISERROR. ISERROR simply returns True or False depending on the result of the VLOOKUP.
=IF(ISERROR(VLOOKUP(DCTM!B4,'DCTM WKSHT'!B:K,10,FALSE)),1,0)

Excel: Count if value is present in 3 columns

How do I count the number of values that are present across ALL THREE columns?
For example, “L160” is the only value that is in all 3 columns, so the formula should equal 1.
Screenshot of values
The following formula will check if the value in C is present at least once in A, at least once in B, and makes sure that the value in C is not blank. If all three conditions are true it will return 1 and it fails it will return 0
=--AND(COUNTIF(A:A,C2)>=1,COUNTIF(B:B,C2)>=1,C2<>"")
Place the above formula in am empty cell and copy down as need be.
You can start, using the Match() function: if the string is found, the location is shown. If not, you get an error message. This return value is checked, using an If() function: if the value is ok (larger than 0), the value 1 is returned, otherwise 0.
=IF(MATCH(C2;A$2:A$39;0)>0;1;0)
The result of this will either be 1 (C2 is present in column A) or #Error (I tried getting 0 but this failed, no problem however).
This you can do three times, and you add the results, something like:
=IF(MATCH(C2;A$2:A$39;0)>0;1;0)
+IF(MATCH(C2;B$2:B$39;0)>0;1;0)
+IF(MATCH(C2;C$2:C$5;0)>0;1;0)
You divide the result by three in order for the successful result being equal to 1.
On that, you apply an IFERROR() function, translating the errors into 0.
Off you go :-)
If one has the new Dynamic Array formula:
=SUMPRODUCT(ISNUMBER(MATCH(UNIQUE(FILTER(C:C,C:C<>"")),A:A,0))*ISNUMBER(MATCH(UNIQUE(FILTER(C:C,C:C<>"")),B:B,0)))
No helper columns needed.

How to select a column IF [duplicate]

Is there a formula that returns a value from the first line matching two or more criteria? For example, "return column C from the first line where column A = x AND column B = y". I'd like to do it without concatenating column A and column B.
Thanks.
True = 1, False = 0
D1 returns 0 because 0 * 1 * 8 = 0
D2 returns 9 because 1 * 1 * 9= 9
This should let you change the criteria:
I use INDEX/MATCH for this. Ex:
I have a table of data and want to return the value in column C where the value in column A is "c" and the value in column B is "h".
I would use the following array formula:
=INDEX($C$1:$C$5,MATCH(1,(($A$1:$A$5="c")*($B$1:$B$5="h")),0))
Commit the formula by pressing Ctrl+Shift+Enter
After entering the formula, you can use Excel's formula auditing tools to step through the evaluation to see how it calculates.
SUMPRODUCT definitely has value when the sum over multiple criteria matches is needed. But the way I read your question, you want something like VLOOKUP that returns the first match. Try this:
For your convenience the formula in G2 is as follows -- requires array entry (Ctrl+Shift+Enter)
[edit: I updated the formula here but not in the screen shot]
=INDEX($C$1:$C$6,MATCH(E2&"|"&F2,$A$1:$A$6&"|"&$B$1:$B$6,0))
Two things to note:
SUMPRODUCT won't work if the result type is not numeric
SUMPRODUCT will return the SUM of results matching the criteria, not the first match (as VLOOKUP does)
Apparently you can use the SUMPRODUCT function.
Actually, I think what he is asking is typical multiple results display option in excel. It can be done using Small, and row function in arrays.
This display all the results that matches the different criteria
Here is an answer that shows how to do this using SUMPRODUCT and table header lookups. The main advantage to this: it works with any value, numeric or otherwise.
So let's say we have headers H1, H2 and H3 on some table called MyTable. And let's say we are entering this into row 1, possibly on another sheet. And we want to match H1, H2 to x, y on that sheet, respectively, while returning the matching value in H3. Then the formula would be as follows:
=INDEX(MyTable[H3], ROUND(SUMPRODUCT(MATCH(TRUE, (MyTable[H1] & MyTable[H2]) = ($x1 & $y1),0)),0),1)
What does it do? The sum-product ensures everything is treated as arrays. So you can contatenate entire table columns together to make an array of concatenated valued, dynamically calculated. And then you can compare these to the existing values in x and y- somehow magically you can compare the concatenated array from the table to the individual concatenation of x & y. Which gives you an array of true false values. Matching that to true yields the first match of the lookup. And then all we need to do is go back and index that in the original table.
Notes
The rounding is just in there to make sure the Index function gets back an integer. I got #N/A values until I rounded.
It might be more instructive to run this through the evaluator to see what's going on...
This can easily be modified to work with a non table - just replace the table references with raw ranges. The tables are clearer though, so use them if possible. I found the original source for this here: http://dailydoseofexcel.com/archives/2009/04/21/vlookup-on-two-columns/. But there was a bug with rouding values to INTs so I fixed that.

Compare two sheets as matrix table

A1:200 B1:260
A2:300 B2:220
A3:400 B3:240
A4:200 B4:300
A5:200 B5:200
I got two tables going on and basically I want to check if row A is greater than 200 AND row B is greater than 250 then count.
So far I have this:
=COUNTIF(A1:A5,">= 200")
but I have no idea how to check if A passes then check B and if so, count it. I'm guessing something to do with IF, AND and maybe a for loop? I'm not familiar with this language at all :x
You want to calculate total count when column A is greater than 200 and B contains cell values greater than 250.
If you want a single value for entire table use countifs,
=COUNTIFS($A$1:$A$5,">200",$B$1:$B$5,">250")
If you want to get the counts in different column (let say C) on each row, then copy and paste below formula in C1 and drag it to C5 cell
=+IF(AND(A1>200,B1>250),1,0)
Where 1 means both conditions are true and 0 means either of condition is false.
However if you want to check first if the first condition is satisfying or not, then you can use below formula:
=+IF(A1>200,IF(B1>250,1,0),2)
Where "1" means true and both the condtion is satisfying , "0" means first condition is satisfying but second is not and "2" means the first condition is not satisfying hence it didn't check the second condition.
Hope this helps

VLOOKUP with two criteria?

Is there a formula that returns a value from the first line matching two or more criteria? For example, "return column C from the first line where column A = x AND column B = y". I'd like to do it without concatenating column A and column B.
Thanks.
True = 1, False = 0
D1 returns 0 because 0 * 1 * 8 = 0
D2 returns 9 because 1 * 1 * 9= 9
This should let you change the criteria:
I use INDEX/MATCH for this. Ex:
I have a table of data and want to return the value in column C where the value in column A is "c" and the value in column B is "h".
I would use the following array formula:
=INDEX($C$1:$C$5,MATCH(1,(($A$1:$A$5="c")*($B$1:$B$5="h")),0))
Commit the formula by pressing Ctrl+Shift+Enter
After entering the formula, you can use Excel's formula auditing tools to step through the evaluation to see how it calculates.
SUMPRODUCT definitely has value when the sum over multiple criteria matches is needed. But the way I read your question, you want something like VLOOKUP that returns the first match. Try this:
For your convenience the formula in G2 is as follows -- requires array entry (Ctrl+Shift+Enter)
[edit: I updated the formula here but not in the screen shot]
=INDEX($C$1:$C$6,MATCH(E2&"|"&F2,$A$1:$A$6&"|"&$B$1:$B$6,0))
Two things to note:
SUMPRODUCT won't work if the result type is not numeric
SUMPRODUCT will return the SUM of results matching the criteria, not the first match (as VLOOKUP does)
Apparently you can use the SUMPRODUCT function.
Actually, I think what he is asking is typical multiple results display option in excel. It can be done using Small, and row function in arrays.
This display all the results that matches the different criteria
Here is an answer that shows how to do this using SUMPRODUCT and table header lookups. The main advantage to this: it works with any value, numeric or otherwise.
So let's say we have headers H1, H2 and H3 on some table called MyTable. And let's say we are entering this into row 1, possibly on another sheet. And we want to match H1, H2 to x, y on that sheet, respectively, while returning the matching value in H3. Then the formula would be as follows:
=INDEX(MyTable[H3], ROUND(SUMPRODUCT(MATCH(TRUE, (MyTable[H1] & MyTable[H2]) = ($x1 & $y1),0)),0),1)
What does it do? The sum-product ensures everything is treated as arrays. So you can contatenate entire table columns together to make an array of concatenated valued, dynamically calculated. And then you can compare these to the existing values in x and y- somehow magically you can compare the concatenated array from the table to the individual concatenation of x & y. Which gives you an array of true false values. Matching that to true yields the first match of the lookup. And then all we need to do is go back and index that in the original table.
Notes
The rounding is just in there to make sure the Index function gets back an integer. I got #N/A values until I rounded.
It might be more instructive to run this through the evaluator to see what's going on...
This can easily be modified to work with a non table - just replace the table references with raw ranges. The tables are clearer though, so use them if possible. I found the original source for this here: http://dailydoseofexcel.com/archives/2009/04/21/vlookup-on-two-columns/. But there was a bug with rouding values to INTs so I fixed that.

Resources