0

I keep getting this error when trying to run this IIF statement.

enter image description here

Here's what I have:

IIF([Explanation] Like "*No Alternative*" Or Like "*1*" Or Like "*least costly room*" Or Like "*best possible rate*" Or Like "*best rate available*" Or Like "*best available rate*" Or Like "*least expensive*" Or Like "*cheapest hotel room*" Or Like "*lowest price*" Or Like "*cheapest rate*", “No Alternative”, IIF([Explanation] Like "*Required location*" Or Like "*2*", “Required Location”, IIF([Explanation] Like "*Least total cost*" Or Like "*3*" Or Like "*most economical*", “Least Total Cost”, “No Alternative”)))
3
  • Here: Or Like "most economical", “Least Total Cost”, “No Alternative” You have commas there you need to seperate out to more like statements Commented Mar 30, 2018 at 14:51
  • "Least Total Cost" is what the output should be if [Explanation] is like the previous string of examples. "No Alternative" is what the output should be if all the three previous IIF conditions were not present. Commented Mar 30, 2018 at 14:56
  • 1
    You need to state the field name before every like, not just the first. Adjust that. Commented Mar 30, 2018 at 14:56

2 Answers 2

3

Instead of

[Explanation] Like "*No Alternative*" Or Like "*1*"

you need

[Explanation] Like "*No Alternative*" Or [Explanation] Like "*1*"
Sign up to request clarification or add additional context in comments.

Comments

1

you should check for [Explanation] in each OR eg:

IIF( ([Explanation] Like "*No Alternative*" 
Or [Explanation] Like "*1*" 
Or [Explanation] Like "*least costly room*" 
Or [Explanation] Like "*best possible rate*" 
Or [Explanation] Like "*best rate available*" 
Or [Explanation] Like "*best available rate*" 
Or [Explanation] Like "*least expensive*" 
Or [Explanation] Like "*cheapest hotel room*" 
Or [Explanation] Like "*lowest price*" 
Or [Explanation] Like "*cheapest rate*"), "No Alternative", 

  IIF( ([Explanation] Like "*Required location*" 
    Or [Explanation] Like "*2*"), "Required Location", 

      IIF( ([Explanation] Like "*Least total cost*" 
        Or [Explanation] Like "*3*" 
        Or [Explanation] Like "*most economical*"), "Least Total Cost",
             "No Alternative")))

4 Comments

That didn't work for me --both adding [Explanation] before each 'Like' and copying the exact statement above. I still get the same message.
are you sure you have not some others part of code that may lead to some problems on IFF ..?? anyway add some () for a better closing of each logical condition ..
also changed with regular double quote the true literal expressions
thank you. I ended up just rewriting it all instead of copying and pasting and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.