Using SQL "IN" Function in Excel - excel

Is there an "IN" type function like the one used in sql that can be used in excel? For example, if i am writing an If statement in excel and I want it to check the contents of a cell for 5 different words can i write something like:
=If(A1=IN("word1","word2","word3","word4","word5"),"YES","NO")

You could use MATCH :
=MATCH(A1, {"word1","word2","word3","word4","word5"}, 0)
which will return the index of the matching item in the array list. The trailing 0 means it should be an exact match. It will return #N/A if it isn't there, so you can tag a IF(ISNA( onto the front to make it behave like your "IN":
=IF(ISNA(MATCH(A1, {"word1","word2","word3","word4","word5"}, 0)),"NO","YES")
Note the change in order of the "YES" and "NO"

=IF(OR(A1={"word1","word2","word3","word4","word5"}),"YES","NO")

I think an improvement on
=IF(OR(A1={"word1","word2","word3","word4","word5"}),"YES","NO")
would be to use
=IF(OR(A1={"word1","word2","word3","word4","word5"}),A1,"NO");
which is more like the SQL's IN clause.

Use the OR function. It operationes very similiar to what you are looking for.
IF(OR(A1="word1",A1="word2",A1="word3")=TRUE,"Yes","No")
Also doesn't require the ctrl+shift+enter when using.

Related

How to extract unique values from an array EXCEPT specified values?

I am already abel to extract unique values, in excel, from an array using this function:
{=INDEX(list,MATCH(0,COUNTIF(uniques,list),0))}
However, I want to specify certain values for excel not to return. Is there any way to specify values that I don't want to be found within the already specified "list"? The ideal outome would be something like this:
I am also using excel version 2101.
Any information is helpful, thanks!
From your example, I ASSUME you want to exclude the lines starting with Round.
Try:
=LET(x,UNIQUE(List),FILTER(x,LEFT(x,5)<>"Round"))
or
=UNIQUE(FILTER(List,(LEFT(List,5)<>"Round")))
I'm not sure if it is more efficient to filter a smaller list, as is done in the first formula; or to avoid using LET as is done in the second formula.
EDIT
This can also be done using FILTERXML and TEXTJOIN which should be present in all Windows versions 2016+
=FILTERXML("<t><s>"&TEXTJOIN("</s><s>",,list)&"</s></t>","//s[not(starts-with(.,'Round')) and not(preceding-sibling::*=.)]")
the xPath
not(starts-with(.,'Round')) : should be obvious
Return only unique values:
and not(preceding-sibling::*=.) : do not return a node if any preceding-sibling matches the current node being tested

How to include Multiple IFs in Excel formula?

I have the formula below that has two IF Statements however it is given an error. Any help is appreciated.
=IF((AND(B11>65,D15>65)),Sheet!D$47,VLOOKUP(D15,Sheet!$A$2:$K$51,4,FALSE)),IF((AND(B11>61,D15>61)),Sheet!D$44,VLOOKUP(D15,Sheet!$A$2:$K$51,4,FALSE))
What I am trying to Achieve is the following:
IF B11>65 and D15 >65 Then select value from D$47. IF B11<65 and D15<65 Then Select value from D$44. Else VLOOKUP(D15,Sheet!$A$2:$K$51,4,FALSE))
You can have multiple IF() calls embedded such as this:
=IF(AND(), Sheet!D$47, IF(AND(), Sheet!D$44, VLOOKUP())
The complete form in your case would be:
=IF(AND(B11>65,D15>65), Sheet!D$47, IF(AND(B11>61,D15>61), Sheet!D$44, VLOOKUP(D15,Sheet!$A$2:$K$51,4,FALSE)))
Basically, this uses the 'Else' clause as a means to add additional clauses. It is possible to do it the other way around but I personally find that harder to read.

Multiple "IF" statements in Excel but using the same phrase look up

I can not figure out how to put 2 of the same IF statement but with a different result in case is not there then to do the second combination.
=IF(C2737="XXX_SF",INDEX(TMParking_8_24!A:A,MATCH(Tracker!J2737&"xxxshortform",TMParking_8_24!F:F,0)),
The above formula is what I'm looking for. Incase xxxshrotform is not there I would like it to search for a xx5shortform. So I added the below to the second part of the formula:
INDEX(TMParking_8_24!A:A,MATCH(Tracker!J2737&"xx5shortform",TMParking_8_24!F:F,0)))
Within the INDEX the xx5shortform exists but it is not finding it.
Use the IFERROR function to pass control over to a second MATCH function if the first is not found.
=IF(C2737="XXX_SF",
INDEX(TMParking_8_24!A:A,
IFERROR(MATCH(Tracker!J2737&"xxxshortform",TMParking_8_24!F:F,0),
MATCH(Tracker!J2737&"xxshortform",TMParking_8_24!F:F,0))), "")
There was no indication as to what to return if C2737 does not equal XXX_SF nor what to do if the second match does not work.

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")

Excel: search multiple strings then return value

I am using the following formula to search for a string and return a value
IF(ISNUMBER(SEARCH("CHA*",B:B),"CINEMA","")
If I want to search for multiple strings whats the formula?, I've tried the following but it isn't returning anything
IF(ISNUMBER(SEARCH({"odeon*","vue*"},B:B),"CINEMA","")
Try this:
=IF(COUNT(SEARCH({"odeon*","vue*"},B:B))>0,"CINEMA","")
Another way:
=IF(OR(ISNUMBER(SEARCH({"odeon*","vue*"},B:B))),"CINEMA","")
Use AND() if you require ALL substrings to match:
=IF(AND(ISNUMBER(SEARCH({"odeon*","vue*"},B:B))),"CINEMA","")
For starters, you're missing a ) on either formula. And for them to work anyway, you should, as Taosique pointed out, use =IF(OR(ISNUMBER(SEARCH( if you need just one substring, or =IF(AND(ISNUMBER(SEARCH( if you require both.
Good luck!

Resources