is Excel function OR() incorrect? - excel

Is there any reason in an Excel spreadsheet the expression OR(TRUE,#N/A) returns #N/A ?
How can we make it work the way we learned at school ie. OR(TRUE, whatever) should equal TRUE ?
so that we can evaluate a logical expression correctly even if not all parameters are known at the time of running, if those unknown are not really required.
Thank you
PS.
i use #N/A where the input is not known yet, it is not meant to be
an error. For instance
"=OR(turnover>1000000,leadtime>90,AND(turnover>500000,leadtime>30),AND(turnover>200000,leadtime>60))"
indicates an item needs special attention either because its
turnover is high or because its lead time is long but i don't
always have inputs for both. Sometimes one of two should suffice.
N/A is used when not known because i haven't found anything better than that. Tried "Unknown" string and AND(TRUE,"Unknown")
returns TRUE, which is not what it should be
i have many expressions which are more complicated than just
OR(x1,x2) so instead of trapping every parameter for error i have
written an udf OOR where OOR(TRUE,whatever even if error) = TRUE.
Just wondering if Microsoft has a better approach i don't know

You can wrap the logicals in an IFERROR that returns FALSE:
=IF(OR(IFERROR(A1=1,FALSE),IFERROR(B1=1,FALSE)),TRUE,FALSE)

You cannot compare to an error without throwing an error. Use ISERROR or ISNA on the cell to see if it contains an error.
=IF(OR(A1=TRUE,ISERROR(A1)), <something if true>, <something if false>)
In the above, you don't need to say A1 = TRUE, simply A1 will return true or false.

Related

So I'm trying to stack up some =if(and( functions in excel, I can't seem to find the problem in the formula used, could anyone help me?

=IF(AND(F2=N2;G2>O2);"No Notificar";"Notificar";IF(AND(F2=N3;G2>O3);"No Notificar";"Notificar";IF(AND(F2=N4;G2>O4);"No Notificar";"Notificar";IF(AND(F2=N5;G2>O5);"No Notificar";"Notificar";IF(AND(F2=N6;G2>O6);"No Notificar";"Notificar";IF(AND(F2=N7;G2>O7);"No Notificar";"Notificar")))))
As #KromeWing said - you've entered too many parameters for an IF formula.
It should have a logical calculation that would return TRUE/FALSE and then what to do if it's TRUE and what to do if it's FALSE.
Currently your formula reads as:
=IF(AND(F2=N2,G2>O2),"No Notificar","Notificar",
IF(AND(F2=N3,G2>O3),"No Notificar","Notificar",
IF(AND(F2=N4,G2>O4),"No Notificar","Notificar",
IF(AND(F2=N5,G2>O5),"No Notificar","Notificar",
IF(AND(F2=N6,G2>O6),"No Notificar","Notificar",
IF(AND(F2=N7,G2>O7),"No Notificar","Notificar")))))
It should look more like:
=IF(AND(F2=N2,G2>O2),"No Notificar",
IF(AND(F2=N3,G2>O3),"No Notificar",
IF(AND(F2=N4,G2>O4),"No Notificar",
IF(AND(F2=N5,G2>O5),"No Notificar",
IF(AND(F2=N6,G2>O6),"No Notificar",
IF(AND(F2=N7,G2>O7),"No Notificar","Notificar"))))))
So if the first equation is TRUE it will show No Notificar, otherwise it will test the second equation. If all equations return FALSE then it will return Notificar.
IF has only 3 parameters.
Your consecutive IF should be the 3rd parameter, there is no 4th parameter in this formula.
You are expecting IF() to accept four arguments instead of three.
I often get messed up by nested ifs, too, and it's usually from having to think too hard.
To make things easier on yourself, both today and next month when you come back to this and have to try to figure out what the heck you were trying to do, try using alt-enter to add a new line within your formula, allowing you to format your formula like this:
=IF(test, valueIfTest,
IF(test2, valueIfTest2,
IF(test3, valueIfTest3,
...
valueIfAllTestsFail
)))
I find that as long as I stick to this format, the hardest part of the syntax is reduced to having the right number of closing parentheses at the end, but thanks to how Excel color-codes matching parentheses, I can manage that even when I'm caffeine-deprived!

How to use IF function with 3 arguments while ignoring blanks

Okay so my question is how do i use IF with 3 arguments while one of the arguments is "Ignore blanks".
If A1 is "Escalation_complaint or "Escalation_request" B1 must show "Escalated".
If A1 is any other text, B1 must show "Solved"
If A1 is blank, B1 must remain empty.
Can someone please help me figure this out?
Your first test must be whether the A1 is empty or not. This must be the first because if you test whether an empty string is contained in another string the answer is always yes. =SEARCH("","Something") returns 1. So, How do you test for an empty cell? I recommend Excel's COUNTA() function but you may prefer testing for "". So, let's say, your first test is this.
=IF(COUNTA(A1), True, False)
Some would say IF(COUNTA(A1)>0, True, False) and that is equivalent. The simple IF(COUNTA(A1) tests for non-zero. Any number other than zero returns True.
So, now you got your basic function. What's supposed to happen if the result is True? What do you want to happen if the result is False? The latter is easy. If the result is False you want a null string returns. So, now your formula looks like this:-
=IF(COUNTA(A1), True, "")
Observe that we simply replaced the False with the desired output. So, what do you want to happen if A1 has something in it, if the first test resulted in True? There are two possibilities. That makes the problem solvable with a single IF. IF A1 has something starting with "Escalation" in it the result should be "escalate", else it should be "solved". So, how do you test for cell content?
=Find("escalation", A1) will not find "Escalation" (with a capital E). Therefore I recommend SEARCH(), which does.
=SEARCH("escalation", A1) should return 1. If it returns 1 your problem is solved because if it returns any other number its not "escalated" but "solved". Unfortunately, there is a third option. It might return an error. In fact it will return an error every time the word isn't found. That gives you a 3-way possibility (1, bigger than 1, or Error) which can't be solved with a single IF. So, I suggest to avoid the error.
=Find("escalation", A1 & "escalation") will find the word "escalation" every time. But it will find it in first position only if the conditions for "Escalate" is met. Therefore the formula for the True condition in the basic formula must be this:-
IF(SEARCH("escalation", A1 & "escalation") = 1, "Escalated", "Solved")
That's it. Assemble the second IF into the first and you're done.
So, using two if(), and minimising the testing you need :
=IF(left(A1,3)="Esc","Escalated",IF(A1="","","Solved"))
Edit: Based on a comment to another answer, if testing for "esc" only could lead to problems then how about:
=IF(left(A1,5)="Escal","Escalated",IF(A1="","","Solved"))
Which will avoid words like "escaped" or "escargot"...
If you know that the text will always be Escalation_complaint or Escalation_request, you can do this with a nested IF query. =IF in Excel takes three parameters: what to verify, result if true, and result if false. You can have another IF statement in the what to do if it returns false section. We can also do an OR() statement to verify both Escalation_complaint and Escalation_request. The result looks like this:
=IF(OR(A1="Escalation_complaint",A1="Escalation_request"),"Escalated",IF(A1="","","Solved"))
The order here is important because you want the "for all other cases" to be in the final IF statement.
If you have a situation where you could also have "Request_escalation" or "complaint_escalation", you should make a more general solution that uses SEARCH or FIND which would allow you to do a more general lookup that allows for more values without having to hardcode them. Here is an example that makes it possible to find the word Escalation anywhere in the cell:
=IF(IFERROR(SEARCH("escalation",A1,1),0)>0, "Escalated", IF(A1="","","Solved"))
Excel have maximum 30 arguments in a formula.
= if (A1=1, "True",if(B1>2,"True", "false"))
Understand this pattern. easy way.
If you no longer understand this, or if your problem has not been resolved, attach a file or screenshot that relates to your problem.

How to use search function with if function

My excel sheet have bank name, IFSC code and account number.
I want to get bank name from IFSC Code. For this I've used the following formula:
=IF(SEARCH("DNB",P17),"DELHI NAGRIK SEHKARI BANK",IF(SEARCH("SBIN",P17),"STATE BANK OF INDIA",IF(SEARCH("PUNB",P17),"PUNJAB NATIONAL BANK",IF(SEARCH("CNRB",P17),"CANARA BANK","TYPE BANK NAME")))).
It works for first option only (here, formula shows 'Delhi Nagrik Bank') and for other option it shows #Value.
Please tell me my mistake.?
I suggest you break your formula into its smaller component parts, and test those, to understand the root cause.
Understanding the problem
SEARCH("DNB",P17) returns a number if found, or an error if not found.
When that error occurs, the IF statement also returns an error. This is because IF expects input of either true or false only.
Also, this is why your formula works in the "DNB" case, but produces an error and doesn't actually test any further cases (e.g. "SBIN").
Solution
You need to update the function used in the IF statement's argument, so that it returns either a logical true or false value.
Conveniently, the ISNUMBER() function returns true if input is a number, and false otherwise.
TLDR
Instead of IF(SEARCH()), use IF(ISNUMBER(SEARCH())). Your formula will then work as intended.

Excel ISNUMBER Function with IF Statement

I have an Excel file I'm working with. There is a column that contains numbers and text, sometimes it's just one or the other. I'm trying to write a function that scans the left most part of the cell to see if it starts with a number. I thought I had it but apparently not. This is what I had:
=IF(ISNUMBER(LEFT(E8,1)), "True", "False")
This continues to throw me a "false" result even though that particular cell, E8, begins with a "3". What am I missing here?
Try this out:
=IF(ISNUMBER(VALUE(LEFT(E8,1))),"True","False")
Using the IF statement is redundant. The most simple and effective way to achieve your desired result is:
=ISNUMBER(--LEFT(E8,1))
It will automatically return TRUE or FALSE
Note that you can achieve what you require with just the following:
=NOT(ISERROR(LEFT(E8)*1))
If you do not LEFT(E8) evaluates to LEFT(E8,1) and multiplication by 1 throws an error on anything non-numeric
If you need your output as strings then update as per below:
IF(NOT(ISERROR(LEFT(E8)*1)),"True","False")
EDIT
Using ISNUMBER() is a good alternative to NOT(ISERROR())
=ISNUMBER(LEFT(A1)*1)
=IF(ISNUMBER(LEFT(A1)*1),"True","False")
=IFERROR(IF(VALUE(LEFT(E8,1)),"TRUE","FALSE"),"FALSE")

Does Excel evaluate both result arguments supplied to the IF function?

Excel's if function takes three arguments, a condition, an if-true value, and an if-false value. Does Excel work out the value of all three arguments, or does it only work out the value of the condition and the corresponding result?
Clarification: I'm not wondering what the result of the if will be, I'm wondering whether or not it calculates the value of all arguments before calculating the result of the function.
This is equivalent to asking whether or not the if function uses lazy or strict evaluation. For example, the following pseudocode:
x = 5;
print x>2 ? "Bigger" : "Smaller" + 1/0
would throw a divide-by-zero exception in a language with fully strict evaluation, as it would evaluate the 1/0, even though the result wouldn't be required for the ?: operator.
In a lazy-evaluation language, the ?: operator would evaluate x>2 before even deciding which expression to evaluate.
The problem is that in Excel, 1/0 produces a legitimate value (which happens to be #DIV/0!) that can exist in expressions. Therefore, simply calling =if(true,1,1/0) doesn't show whether Excel is evaluating the 1/0 or not.
Very east to test
? iif(true, 1, 1/0) 'run-time error: division by zero
I'm assuming you really mean iif() - in VBA this does not "short-circuit", so you should use If..Then..Else..End If in cases where that could be a problem.
Ok - testing what you really asked:
'In a VBA module
Function TruePart()
MsgBox "True part"
TruePart = "True"
End Function
Function FalsePart()
MsgBox "False part"
FalsePart = "False"
End Function
In a cell: =IF(TRUE,truepart(),falsepart())
Only get one msgbox per calculation of the IF() cell.
As further validation, this gives you two msgbox - one for each:
Sub Tester()
Debug.Print IIf(True, TruePart(), FalsePart())
End Sub
It does not.
Excel 2013 only evaluates the necessary code.
I had a very complex and time consuming cell formula to copy through a couple hundred thousand rows. It would take a few hours to calculate. But fortunately, it was easy to determine based on some other criteria when the result would be zero.
So using an If Statement to avoid the calculation when other criteria suggested it must be zero, and performing the calculation only when necessary sped up the process immensely, cutting processing time to about 10% of the previous.
If Excel were evaluating both expressions, the If Statement would only have added complexity and time.
A couple simple tests:
=IF(TRUE,1,1/0)
=IF(FALSE,1/0,1)
Neither results in a div/0 error, so one could conclude only the corresponding result of the condition is actually evaluated. Obviously the condition itself also must be evaluated.
In more complex formulae you could also use the Evaluate Formula tool to watch how IF statements are parsed.
Excel seems to use eager evaluation for the IF() function (i. e. always evaluates all three arguments). To test without VBA, turn on automatic workbook calculation and enter into a new workbook's cell:
=IF(TRUE, 0, RAND())
Save and close workbook. Open the workbook again and close again, and Excel will show the "save changes" prompt because volatile function RAND() has been evaluated.
Change RAND() to 1 and Excel does not show the prompt.
I have the opposite answer to Tim, based instead on XL 2010 If Function:
=IF(TRUE,1,1/0)
doesn't yield a #DIV/0 error,
=IF(FALSE,1,1/0)
does. Also, my reading implies that only the appropriate condition is evaluated.

Resources