I'm using a IF AND statement to check a simple statement, for example A>B&BB, I get FALSE. How is that even possible?
My data sample:
It works both ways if I use AND(), but I prefer to use &.
You may "prefer to use &" but unfortunately this operator in Excel has a different meaning: string concatenation. If you dont want to use AND, you can use * instead; but you will need to parenthesize the terms.
=IF((A2>C2)*(C2<B2), TRUE, FALSE)
Use AND():
IF(AND(A2>C2,C2<B2),TRUE,FALSE)
Or as was written in comments you can use multiplication:
IF((A2>C2)*(C2<B2),TRUE,FALSE)
FYI - you don't need IF().
If you use AND(A2>C2,C2<B2) the result will be Boolean (TRUE/FALSE).
Related
In Excel, I have three formulas/statements I'd like to merge into one. I've listed the statements below. Is there a way to merge all three formulas into one? I'd like to learn how to write the logic to do this. Thanks.
=IF(COUNTIF($B:$B,$A2)=1, "MATCH")
=IF(COUNTIF($B:$B,$A2)>1, "DUPLICATE")
=IF(COUNTIF($B:$B,$A2)<1, "NO MATCH")
The syntax of the IF function is IF(true-false-condition, value-if-condition-true, value-if-condition-false) (where either missing value-if defaults to 0).
3-way (or more) IF conditionals can be written by nesting multiple boolean IF's, for example:
=IF(COUNTIF($B:$B,$A2)>1, "DUPLICATE", IF(COUNTIF($B:$B,$A2)=1, "MATCH", "NO MATCH"))
Also consider good practice of trapping the default 'else' case. The above answer does not do this, and it assumes your input will always be one of your stated cases (=1, <1 or >1) so omits the final IF condition. In that example this will not error because the evaluations will always return true or false, but this may not behave as expected if an input is a different data type, null set, etc. In the stated answer, this unexpected behaviour will "fail silently" which is a potential issue.
Instead, try:
=IF(COUNTIF($B:$B,$A2)>1, "DUPLICATE", IF(COUNTIF($B:$B,$A2)=1, "MATCH", IF(COUNTIF($B:$B,$A2)<1, "NO MATCH", "ERROR")))
In implementation you would replace "ERROR" with your chosen error handling method.
You could also look at the following Excel functions, as an alternative to nesting multiple IF functions:
SWITCH:
=SWITCH(expression, value1, result1, [default or value2, result2],…[default or value3, result3])
IFS:
=IFS (test1, value1, [test2, value2], ...)
Some of these are newer than others so be sure to test to your version of Excel (and consider compatibility with any other possible users of your file).
In a now deleted question, the OP asked to return 1.3 and 0.4 from 1^1.3%2^0.4.
I immediately thought FILTERXML.
I was able to do it with:
=MID(FILTERXML("<a><b>"&SUBSTITUTE(A1,"%","</b><b>")&"</b></a>","//b"),FIND("^",FILTERXML("<a><b>"&SUBSTITUTE(A1,"%","</b><b>")&"</b></a>","//b"))+1,99)
But that seemed too repetative.
I found substring-after in XPATH 1.0, but cannot get it to do what I want. I first tried:
=FILTERXML("<a><b>"&SUBSTITUTE(A1,"%","</b><b>")&"</b></a>","//b[substring-after(., '^')]")
But that returned both full strings and :
=FILTERXML("<a><b>"&SUBSTITUTE(A1,"%","</b><b>")&"</b></a>","substring-after(//b, '^')")
Just returned an error.
Is there a way to use only FILTERXML to return the desired numbers?
Unfortunately XPATH in Excel cannot seem to return reworked values, instead use FILTERXML for filtering and returning those nodes of interest. Reworking those nodes need to be done outside the function.
If you are intested in a single FILTERXML usage, I'd suggest a double SUBSTITUTE:
=FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(A1,"^","^%"),"%","</b><b>")&"</b></a>","//b[contains(preceding::*[1],'^')]")
Or:
=FILTERXML("<a><b>"&SUBSTITUTE(SUBSTITUTE(A1,"^","^%"),"%","</b><b>")&"</b></a>","//b[.*0=0]")
Might you be interested in filtering through FILTERXML. Maybe this would interest you?
I want to remove all the characters from a string expect whatever character is between a certain set of characters. So for example I have the input of Grade:2/2014-2015 and I want the output of just the grade, 2.
I'm thinking that I need to use the FIND function to grab whatever is between the : and the / , this also needs to work with double characters such 10 however I believe that it would work so long as the defining values with the FIND function are correct.
Unfortunately I am totally lost on this when using the FIND function however if there is another function that would work better I could probably figure it out myself if I knew what function.
It's not particularly elegant but =MID(A1,FIND(":",A1)+1,FIND("/",A1) - FIND(":",A1) - 1) would work.
MID takes start and length,FIND returns the index of a given character.
Edit:
As pointed out, "Grade:" is fixed length so the following would work just as well:
=MID(A1,7,FIND("/",A1) - 7)
You could use LEFT() to remove "Grade:"
And then use and then use LEFTB() to remove the year.
Look at this link here. This is the way I would go about it.
=SUBSTITUTE(SUBSTITUTE(C4, "Grade:", ""), "/2014-2015", "")
where C4 is the name of your cell.
I'm having trouble trying to use replace characters in MS excel. Help says * and ? can both replace characters, but if I try using them in IF, I don't get correct results.
For example:
A1="something"
=IF(A1="*mething";"yes";"no")
I always get no... How to use * correctly?
wildcards don't work with comparison operators like =
To achieve what you want you can use COUNTIF which does accept wildcards, i.e.
=IF(COUNTIF(A1;"*mething")>0;"yes";"no")
or RIGHT function like
=IF(RIGHT(A1;7)="mething";"yes";"no")
Wildcards cannot be used in this context. Use something like:
=IF(ISERROR(FIND("mething",A1)),"No","Yes")
Is there any functionality in IDL that will allow it to evaluate a a string as code?
Or, failing that, is there a nice, dynamic way of including /KEYWORD in functions? For example, if I wanted to ask them for what type of map projection the user wants, is there a way to do it nicely, without large if/case statements for the /Projection_Type keyword it needs?
With even a small number of user options, the combinations would cause if/case statements to get out of hand very quickly to handle all the possible options.
The best bet is to use a case statement because you can't trust that your user is going to type in the same string for Projection_Type that you're expecting as in the keyword.
Though if you are set on doing something like this, there is the EXECUTE function that treats a string as an IDL statement:
Result = EXECUTE(String [, QuietCompile] [, QuietExecution])
Edited to add, there's also CALL_FUNCTION and CALL_PROCEDURE that are faster but maybe less flexible. Look them all up in the IDL help and see what works for you.