Writing an If statement with multiple OR
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
How can I write an if then statement which has multiple conditions in it? I tried using || instead of "or" but it didn't work. Is there any way to write this logic?
For eg:
if site name = "Yahoo" OR "Google"
then "X"
Elseif site name = "CNN" OR "CBS"
then "Y"
ELSEIF "Z" endif
Solved! Go to Solution.
- Labels:
- Predictive Analysis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
if [site name] = "Yahoo" OR [site name] = "Google" then "X" ELSEIF [site name] = "CNN" OR [site name] = "CBS" then "Y" ELSE "Z" ENDIF
Think of the "OR" as an operator on two logical statements, so the code before and after should each evaluate to TRUE or FALSE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I'm not at my computer, but you can certainly do something like
IF [siteName] == "Google" OR [siteName] == "Yahoo" THEN
... you could also check for IN... e.g.
IF [siteName] IN ("Google","Yahoo") THEN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Worth considering the SWITCH statement as well:
SWITCH([site name],"Z", ."Yahoo","X" ,"Google","X", ,"CNN","Y", ,"CBS","Y" )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Too many commas in my formula. Fixed version:
SWITCH([site name],"Z" ,"Yahoo","X" ,"Google","X" ,"CNN","Y" ,"CBS","Y" )
(Shouldn't have written it on a mobile!)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
In this case and in a lot of other cases Switch formula is better and it is shorter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I want to do something similar to this, but use the contain formula as the field may have other information as well. So I tried the following, but it does not bring out the results I'm expecting...
if contains("Yahoo",[site name]) OR contains("Google",[site name]) then "X" ELSE "Z" ENDIF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I am having the same issue as well. Does anyone have a resolution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
