# APPLICATION OF IF AND IIF FUNCTION

January 16, 2019

Both IF and IIF functions are logical functions. And like all other logical functions, they allow developers to test whether certain condition is true or false (boolean logic).

For example, testing whether Sales for various sales agents is below or above target.

While these two functions offer the same solution, there exist a small difference in way of their application. Therefore, this article seeks to explore how the two functions differ.

IF Function

IF function tests an expression, returning one variable if the expression is TRUE and another variable if the expression is FALSE or OTHERWISE.

E.g.

IF(x>0,a,b), the interpretation to this expression is. If x is greater than 0, then return ‘a’ else if x is not greater than zero (x<=0 or x=null) then return ‘b’.

{Written:  If x>0 then ‘a’ else ‘b’ END }

IIF Function

IIF function on the other hand tests an expression, returning one variable if the expression is TRUE and another variable if the expression is FALSE and another variable if the expression is neither TRUE nor FALSE. (Returns Null if the third expression is not specified).

E.g.

IIF(x>0,a,b), the interpretation to this expression is, if x is greater than 0 then return ‘a’, else if x is not greater than 0 then return ‘b’,  else if x is neither greater than zero (x>0) nor less or equal to zero (x<=0) then ‘Null’.

{Written: IIF(x>0,’a’,’b’)}

A Complete (IIF) function would be written.

IIF(x>0,a,b,c), interpreted as, if x is greater than 0 then return ‘a’, else if x is not greater than 0 then ‘b’, else if x is neither greater than zero (x>0) nor less or equal to zero (x<=0) then return ‘c’.

{Written: IIF(x>0,’a’,’b’,’c’)}

Summary of the functions.