Can someone articulate the difference between the If Then Statement and the Inline If Statement? I understand how to write each, but I am trying to understand why both are needed because they seem to be identical in function but just offer two options based on user preference. I am sure it depends on who you ask as to what a person prefers, but I'm curious if there is an instance where one would actually perform a function where the other would not. Thank you!
Solved! Go to Solution.
Hi @djodts
For me, it depends on the complexity of the statement. If there are multiple OR or AND clauses involved, then I'm inclined to use the IF/THEN/ELSE over the IIF.
If it's a simpler case of checking a condition for true or false, then I go with the IIF. Easier for me in terms of fewer pieces to remember (and being a Tableau user, having to remember to use ENDIF and not simply END).
If there are many simple conditions to test, I actually prefer SWITCH to either IIF or IF/THEN/ELSE.
Hope that offers some insight!!
Cheers,
Esther
Thank you for your insight!
Something to keep in mind with in-line IF statements … in some languages IIF() always evaluates both true part and false part, even though it returns only one of them possibly leading to undesirable side effects and slower execution whereas the IF...THEN...ELSE construct, while textually longer, only evaluates the true/false parts at runtime based upon the flow of logic.
For simple Boolean logic with a smaller number of records it may be a non-issue. For complicated logic there could be unintended consequences and for large number of records the incremental increase in execution time on each record may add up.