from LOOKUP function to VLOOKUP - excel

I'm trying to use VLOOKUP excel function instead of LOOKUP.
I've read VLOOKUP is well optimized but I'm not able to adjust it.
Any help please?
Following function return:
1 if first condition met is >
-1 if first condition met is <
=LOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10)))
Scope of function is: looking to E10 value, searching on range E1:E9 starting from bottom to top, if firstly appear a number > or < of E10, returning +1 or -1
Example 1
E1 = 6
E2 = 5
E3 = 5
E4 = 4
E5 = 6
E6 = 6
E7 = 5
E8 = 8
E9 = 8
If E10 = 8
Result is -1 because first value found is smaller than E10 (starting from E9 and going up)
If E10 = 7
Result is 1 because first value found is bigger than E10 (starting from E9 and going up)
??
=VLOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10));1)
or any other function instead of LOOKUP?

Previous supposed solution works correctly
=VLOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10));1)
but formula needs to be entered with:
CTRL+SHIFT+ENTER
I've tried with MATCH but to me result to don't work correctly.
Any other ideas?

Returning to my first function:
=LOOKUP(2,1/((E1:E9>E10)-(E1:E9<E10)))
I've scomposed it, to understand how it works, to find others possible solutions.
Firstly Excel convert my condition into TRUE and FALSE
IF E10=8
=LOOKUP(2,1/((FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)-(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE)))
Next it converts TRUE and FALSE into 1 and 0
=LOOKUP(2,1/((0,0,0,0,0,0,0,0,0)-(1,1,1,1,1,1,1,0,0)))
Next it makes "-" operation obtaining:
=LOOKUP(2,1/(-1,-1,-1,-1,-1,-1,-1,0,0))
Next it converts into arrays:
=LOOKUP(2,{-1,-1,-1,-1,-1,-1,-1,#Div/0!,#Div/0!},ROW(E1:E9))
Next converts also ROW(E1:E9) into arrays obtaining:
=LOOKUP(2,{-1,-1,-1,-1,-1,-1,-1,#Div/0!,#Div/0!},{1,2,3,4,5,6,7,8,9})
To conclude looks from bottom to top of range, searching for a value close to 2, returnig -1 because E7=5 and is smaller than E10=8
So now, understanding how Excel elaborates is possible to use following function to obtain arrays:
=INDEX(1/((E1:E9>E10)-(E1:E9<E10)),0)
resulting in the same:
{-1,-1,-1,-1,-1,-1,-1,#Div/0!,#Div/0!}
and using previous result combined with VLOOKUP, to get same result of LOOKUP function, but accepting it whitout CTRL+SHIFT+ENTER that was my goal
=VLOOKUP(2,INDEX(1/((E1:E9>E10)-(E1:E9<E10)),0),1)

Related

Count how many matches in the same row across 3 columns

I hope someone can help, I am looking for a formula solution to the following problem if possible.
I have a column of people's names, and for each of those people I have 3 columns of data from 3 different sources - I need to determine how many times the data in those 3 columns matches for each person. After extensive Googling, I could only find solutions where the result is summarised in a cell derived from a COUNTIF range, however I need the results summarised in the same row for each person.
For example:
"Dave" is in cell A2, his results were: column B2 = FAIL, C2 = PASS and D2 = PASS - so in this instance we have 2 matches as there were 2 passes.
"Sue" is in cell A3, her results were: column B3 = FAIL, C3 = FAIL and D3 = FAIL - so in this instance we have 3 matches as there were 3 Fails.
"Colin" is in cell A4, his results were: column B4 = TBA, C4 = FAIL and D4 = PASS- so in this instance we have 0 matches as none of the results match.
Ideally, I would like the number of matches listed down in column E for each individual person, so Dave's matching results would be cell E2, Sue's would be in E3 and Dave's in E4.
Many thanks in advance for your help.
Kindest regards,
TE
You could try:
Formula in E1:
=INDEX({0,2,3},MAX(COUNTIF(B1:D1,B1:D1)))
A bit of explaination for those who are curious:
COUNTIF(B1:D1,B1:D1) - Will result in an array of three values (1 per column), on how often these values appear in the three cells.
MAX() - Get's the max value from the previous array.
INDEX({0,2,3}) - Since the outcome of MAX() can only be 1-3 we can feed this as the row parameter into an INDEX() function. This will then result in either 0, 2 or 3.
A little less verbose and possibly more explicit would be:
=MIN(((B1=C1)+(C1=D1)+(B1=D1))*2,3)
With this last formula we use the fact that TRUE and FALSE are the equivalent of 1 and 0, and therefor we can add multiple boolean values. With some math we can then get our wanted result.
You can use IF() MAX() and COUNTIF combined.
In E2:
=IF(MAX(COUNTIF(B2:D2,B2),COUNTIF(B2:D2,C2),COUNTIF(B2:D2,D2))=1,0,MAX(COUNTIF(B2:D2,B2),COUNTIF(B2:D2,C2),COUNTIF(B2:D2,D2)))
So it does three separate countif to see how many is "duplicated" from each cell.
Takes the max of them and compare against 1, if that is true then return 0, else return what the max value was.
Would something like this work, in column E?
=if(countif(B2:D2,B2)=3,3,if(countif(B2:D2,B2)=2,2,if(countif(B2:D2,C2)=2,2,0)))
Let me know if that works for you.

Excel formula if returns false

I have the following formula:
=IF(I2=0;IF(D2="*CONTADO*";K2=I2;K2=7);K2=I2)
For some reason it returns FALSE, where it should copy the value of I2 or else make it 7.
Aside of that, I don't know if the right way to make a "contains" is just asterisk inside the quotes.
EDIT:
formula now reads as:
=IF(I2=0;IF(OR(ISNUMBER(SEARCH("ALBARAN";D2));ISNUMBER(SEARCH("CONTADO";D2)));I2;7);I2)
It returns false when it matches the searched words in the cells.
I did a small test with
=ESNUMERO(BUSCAR("CLAVIJA";D3))
(to clarify it, Spanish Excel translates every formula name (sigh). ESNUMERO is ISNUMBER and BUSCAR is SEARCH. I've been translating it the whole time for your understanding.)
and did an auditory of the formula. It gets a #N/A when finding "CLAVIJA" even in the cell reads just like that. The value of D3 is "CLAVIJA MULTIPLE 10-16A T.T.LA".
Here in image you can see, you can achieve your desired results, I have done with 3 test cases
FORMULA TO DO =IF(I2=0,IF9D2="CONDTADO",12,7),I2)
B2 0 D2 *CANTADO* I2 0 K2 0 L2 OUTER AND INNER IFS ARE TRUE
B3 3 D3 *CANTADO* I3 3 K3 3 L3 0 OUTER IF IS FALSE
b4 7 D4 *CANTAD* I4 0 K4 7 L4 0 OUTER IF IS TRUE BUT INNER IS FALSE
Solved by replacing SEARCH by FIND.

COUNTIF with IFERROR in the range

I have the following Excel spreadsheet:
A B C
1 50 20 =IFERROR(A1/B1,"") = 2.5
2 60 0 =IFERROR(A2/B2,"") = ""
3 80 0 =IFERROR(A3/B3,"") = ""
4 10 50 =IFERROR(A4/B4,"") = 0.2
5
6 COUNT: 2
7
In Cell C6 I want to count the number of items in the list which are not " " according to Column C.
I tried to do this with the following formula:
=COUNTIF(C1:C4;"<>""")
However, this formula gives me back the value 4 instead of 2.
Therefore, I guess the issue is related to the IFERROR functions which I use in Column C.
Do you have any idea how I have to change the COUNTIF formula to only count the cells without " "?
I know - in this specific case - I could solve the issue by using the COUNTIF formula over Column B. However, I would prepfer a solution that goes over Column C.
Instead of COUNTIF use SUMPRODUCT as
=SUMPRODUCT((C1:C4<>"")*1)
This can be tricky. I usually count the blanks using COUNTBLANK and take that away from the total count
`=COUNTA(D1:D4)-COUNTBLANK(D1:D4)`
Also because in this case your output is the result of a division you could use =COUNTIF(D1:D4,">-1") to count everything with a value zero or above.
Please see https://www.ablebits.com/office-addins-blog/2014/07/02/excel-countif-examples/#countif-blank
In your example, the formula could be
=COUNTIF(C1:C4;"")

Excel: CountIf (cell1 > cell2 AND cell3 > cell4)

I need to compare two sets of two columns and find the count of number of IDs that match a certain criteria.
A B C D E
ID: ListNum: RefNum: List2Num: Ref2Num:
1 10 5 12 6
2 3 7 10 2
3 12 8 1 5
4 2 15 13 4
5 4 11 2 8
6 6 9 1 3
Let's say that the cell containing ID = "1" is A2 and it goes down to A7
I have to count the number of IDs that have a ListNum that is higher than the RefNum AND also have a List2Num that is higher than Ref2Num. Both criteria must be satisfied in order to count the ID.
I used the following formula: =COUNT(IF(B2:B7 > C2:C7) & (D2:D7 > E2:E7))
I get a value, but it's not the right count (it's taking the total for both conditions rather than only counting it once). The final answer should be 1. Any help would be appreciated, thank you!
One reason why yours didn't work: In your formula you use & to mean AND, but & actually concatenate strings.
Option 1: Array Formula
IF and AND don't work on arrays so a normal formula containing them won't work. So use an array formula instead:
You need to enter this as an array formula (you need to press control-shift-enter instead of enter when you put the formula in):
=SUM((B2:B7 > C2:C7)*(D2:D7 > E2:E7))
When it is in the cell it will display in braces to show it is an array formula. Like so:
{=SUM((B2:B7 > C2:C7)*(D2:D7 > E2:E7))}
In this formula the X>Y will return 1 or 0 for true or false. So multiplication is the same as AND and addition is the same as OR. Then (B2:B7 > C2:C7)*(D2:D7 > E2:E7) means B2:B7 > C2:C7 AND D2:D7 > E2:E7 and it returns an array of 1 and 0 which are then summed up to get the count.
Option 2: SUMPRODUCT
There is a normal function whose sole purpose is to multiply arrays together and then add them up the same way as the array formula does: SUMPRODUCT
The problem with SUMPRODUCT is that the arrays must be numbers and not logical true and false values so any of these works:
=SUMPRODUCT(--(B2:B7 > C2:C7),--(D2:D7 > E2:E7))
=SUMPRODUCT((B2:B7 > C2:C7)*1,(D2:D7 > E2:E7)*1)
=SUMPRODUCT((B2:B7 > C2:C7)+0,(D2:D7 > E2:E7)+0)
And this does not:
=SUMPRODUCT((B2:B7 > C2:C7),(D2:D7 > E2:E7))
But SUMPRODUCT is a normal function so you don't need to enter it with control-shift-enter.
Try entering this formula into cell F1:
=IF(AND(B1 > C1, D1 > E1), 1, 0)
Then just take the sum of the F column for however many rows you really have, and you should be left with the answer (which is 1 for the sample data you gave above).
If you put a simple AND formula next to your table, you can autofill that all the way down. Next, you could count the number of True values in that column (see pic). You could combine into an IF statement as Tim suggests.
The two formulas would be
"=AND(B2>C2,D2>E2)"
"=COUNTIF(G2:G7,TRUE)"
Link to picture of possible solution

How to write formula in Excel for my requirement

my requirement as follows:
if a5 = 'a' then b5 = 1
if a5 = 'b' then b5 = 2
if a5 = 'c' then b5 = 3
if a5 = 'd' then b5 = 4
if a5 = 'e' then b5 = 5
else enter correct letter
total no. of conditions are more than 5 as of now and then i need to put default msg for this like 'ENTER CORRECT LETTER '
Excel's IF statement is IF(condition, trueValue, FalseValue). You can nest them to accomplish if-else chains via IF(condition1, trueValue, IF(elseCondition, elseTrue, defaultValue))
Formulas are entered in a cell in Excel by starting the cell's contents with an equals sign.
Conditions of equality in Excel use single equals comparison, not double equals.
There are other ways to approach the problem; if you had a range defined of valid entries, for example, MATCH would be useful for finding the position of a matching cell within that range.
=IF(A5="a",1,
IF(A5="b",2,
IF(A5="c",3,
IF(A5="d",4,
IF(A5="e",5,"Enter Correct Letter")))))
Insert this into cell B5
=IF(OR(CODE(A5)<97,CODE(A5)>101),"ENTER CORRECT LETTER",CODE(A5)-96)
you can see example implimentation in this sheet. Let me know if it helps or you need further explanation.
=IF(ISERROR(FIND(A5,"ABCDE")),"Enter correct letter",CODE(A5)-64)
This will work with as many letters as you want.

Resources