case()

Read(2051) Label: return result, return null,

Description:

Return the corresponding value of the expression whose value is equal to the result of a specific expression.

Syntax:

case(x,x1:y1,…,xk:yk;y)

Note:

This function computes from left to right, beginning from the conditional expression x. Then match the result of expression x with each expression after it in turn. If there is any expression xk that is equal to the result of x, return the result of yk and stop computation.

 

If there is no eligible expression xk but there exists a default expression y, then return the result of y; otherwise, return null.

Parameter:

x

Conditional expression

xk

Value expression

yk

Result expression

y

Default expression

Example:

 

A

 

1

=3

 

2

=case(A1,1:"Dept 1",2:"Dept 2",3:"Dept 3";"Admin Dept")

Return Dept 3.

3

=4

 

4

=case(A3,1:"Dept 1",2:"Dept 2",3:"Dept 3",4:;"Admin Dept")

Return null.

5

=case(A3,1:"Dept 1",2:"Dept 2",3:"Dept 3";"Admin Dept")

Return Admin Dept.

6

=case(A3,1:"Dept 1",2:"Dept 2",3:"Dept 3";)

Return null.

Related function:

if()

between()