if()

Description:

Calculate boolean expressions from left to right. if the result is true, return true value; otherwise return default value or false value.

Syntax:

if(a)

If a is true, then return true. Otherwise, return false

if(a,b,c)

If a is non-null and non-false, then return b; otherwise return c, which is null by default.

if(x1:y1,…,xk:yk;y)

Equivalent to if(x1,y1,if(x2,y2,…,if(xk,yk,y)))

Note:

This function calculates from left to right, and returns different values based on the different results of computing the boolean expressions. Return the corresponding result for the first expression whose value is trure and ignore other boolean expressions. If none of the boolean expression has true value, but there is a default value expression, then return the default value; if there is no such a default value expression, return null.

Parameters:

a

Boolean expression

b

Value expression. If the result of a is true, then return the result of b

c

Value expresssion. If the result of a is false, then return the result of c

xk

Boolean expression

yk

Value expression. If the result of xk is true, then return its result.

y

Default value expression. If all the results of boolean expressions are false, then return the result of this expression.

Return value:

The data type is dynamic, and is determined by the result of value expression. If the corresponding value expression is absent, then return null.

Example:

 

A

 

1

=if(2>1,"Truth","Fallacy")

Truth

2

=85

 

3

=if(A2>90:"Excellent",A2>80:"Good",A2>60:"Passed","Failed")

Good

4

>A2=300

 

5

=if(A2>100:,A2>90:"Excellent",A2>80:"Good",A2>60:"Passed","Failed")

null

6

=if(A2>100)

true

Related functions:

case()

between()