Question

Column1 Column2 Column3 Column4
A       0       C       100%
B       0       B       
C       ok      D       100%
D       ok              100%
E       no      A       
F       ok      F       100%

I want to create the formula to make the column 2 get the value from column1 and look it for in column 3 if it didn't find it, write no; if it found the value, look for the value in column4 if 100%, write ok, if didn't find 100%, write 0.

I hope you help..

Was it helpful?

Solution

You can use MATCH to check if the value from column 1 is in column 3 (MATCH returns a number when there is a match, an error otherwise), then VLOOKUP to get the percentage, all within IF statements:

=IF(ISNUMBER(MATCH(A2, C:C, 0)), IF(VLOOKUP(A2, C:D, 2, 0)=1, "ok", 0), "no")

The above assumes that the values in column 4 are numeric values formatted as percentages.


VLOOKUP works as follows:

VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

lookup_value is the value you're searching.

table_array is the table in which the search will be performed and also from where the result will be pulled from. The lookup_value will be searched for in the first column of the table_array. The result will be pulled from the col_index_numth column in the table_array.

[range_lookup] will decide whether the search will be an exact search or an approximate search.

In the above formula, the VLOOKUP looks for the value from A2, into column C, and returns the corresponding value from the 2nd column in table C:D (i.e. from column D) and ensures that this is an exact search (0 means exact, 1 means approximate).


As per discussion with OP, turns out that Column1 and Column3 were 3 separate columns that needed to be checked for. Since MATCH and VLOOKUP can only check 1 column at a time (unless having recourse to array invocation), COUNTIFS would probably be more appropriate:

=IF(COUNTIFS(Sheet3!$B$13:$B$289,E5,Sheet3!$C$13:$C$289,F5,Sheet3!$D$13:$D$289,G5)=0,"no",IF(SUMIFS(Sheet3!N$13:N$289,Sheet3!$B$13:$B$289,E5,Sheet3!$C$13:$C$289,F5,Sheet3!$D$13:$D$289,G5)=1,"ok",0))

The above formula is what I've come up with which I believe is working for the provided sample data.

OTHER TIPS

I would recommend the use of a countif function. If you format your data as a table with the headers "Column1", "Column2", etc., then you can use a formula like this in Column2

=IF(COUNTIF([Column3],[@Column1])>0,IF([@Column4]=1,"ok",0),"no")

What we're doing is counting the number of instances of the first column (let's say "A") in the third column. If we find more than one instance (>0), then this expression evaluates to true.

=IF(COUNTIF([Column3],[@Column1])>0,

That takes us to the second "IF" statement where we check if the row that matches ours is equal to 1 (100% in percentage terms), and if that is true, we put "ok" in our cell. If that is not true (but we did find a reference to "A"), then we put 0 in our cell.

=IF(COUNTIF([Column3],[@Column1])>0,IF([@Column4]=1,"ok",0

And of course, if we didn't find "A" in the first place, we just put "no" in our cell.

=IF(COUNTIF([Column3],[@Column1])>0,IF([@Column4]=1,"ok",0),"no")

If this is a simple range, then your formula for the first cell in Column2 would look lie this

=IF(COUNTIF($C$2:$C$7,A2),IF(D2=1,"ok",0),"no")

Cell 2 would look like this...

=IF(COUNTIF($C$2:$C$7,A3),IF(D3=1,"ok",0),"no")

etc, etc. If the "100%" is stored as text in your last column, then you can just set the second "IF" statement to look for the text "100%" instead of the number 1.

EDIT: It seems I have misunderstood the question slightly. I have left my original answers above for reference. Here are revised formulas that will provide the correct results.

Table:

=IF(COUNTIF([Column3],[@Column1]),IF(COUNTIFS([Column3],[@Column1],[Column4],1)>0,"ok",0),"no")

So quickly covering the changes. Basically, by using the countifs, we are now counting all cells that equal our match (let's say "A") and also have 100% in the last column. If the count of these is greater than 0, we put "ok", otherwise 0.

IF(COUNTIFS([Column3],[@Column1],[Column4],1)>0,"ok",0)

Range:

=IF(COUNTIF($C$2:$C$7,A2),IF(COUNTIFS($C$2:$C$7,A2,$D$2:$D$7,1)>0,"ok",0),"no")

Of course, this may not be as elegant as VLOOKUP, but hopefully it at least provides an alternative way to approach the problem.

References: excel if, excel countif, excel operators, excel tables, excel countifs

TRY THIS:

=IF(IFERROR(VLOOKUP(A2,C:C,1,0),1)=1,"NO",IF(VLOOKUP(A2,C:D,2,0)=1,"OK",0))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top