Inline if Statements

Inline if statements are alternatives to if...else statements. They use the conditional operator (?) to represent if statements and a colon (:) to representelse clauses. Such statements require three operands:

condition ? expr1 : expr2
  • condition—An expression that evaluates to true or false

  • expr1, expr2—Expressions with values of any type

If condition is true, the value of expr1 is returned; if condition is false, the value of expr2 is returned.

You should place the condition in parentheses and each expression in single or double quotes:

((condition == value)?'expr1':'expr2')


You can safely eliminate the condition parentheses, but omitting the quotes can cause problems.

Numbers do not require quotes.


For example, to display one message if a variable is true and another message if the variable is false, you can use this statement:

( isMember ? 'Member' : 'Not a member')

In this case, if isMember is true, Member is returned. If isMember is false, Not a Member is returned.

You can also use the comparison operator:

((isMember == 'Yes' ) ? 'Member' : 'Not a member')

In this case, if isMember equals the string Yes,Member is returned. If isMember does not equal the string Yes, Not a Member is returned.

If you want to nest inline if statements, (that is, use one inline if statement as an expression for another inline if statement), enclose the nested inline if statements in parentheses:

(1 != 1 ? 'Not Equal' : (1 < 1 ? 'Less Than': 'Equal') )

In this case, if 1 does not equal 1, the second inline if statement is evaluated as part of the else clause of the first inline if statement. If 1 evaluates as less than 1, the string Less Than is returned. Because 1 equals 1, the string Equal is returned from the else clause of the second inline if statement.


If you open a Release 5.5 document in Interactive Reporting Release 6.x and the document contains computed columns with nested if...else statements, the Interactive Reporting JavaScript engine converts the if...else syntax to the inline if statement syntax. The conversion process does not change the meaning or value of the original if...else statement.