SWITCH function

 

The Klipfolio SWITCH function can be used to perform different functions or return different values depending on the data provided.

The syntax for the SWITCH function is:

SWITCH ( data , case, value )

Where the case and value parameter pair is repeated as needed.

Parameters

data The set of values. vector
case The value to be evaluated as either true or false.  scalar
value The value to be returned if the case is true. vector

SWITCH example

 

A

B

1 Monday 10
1 Tuesday 15
1 Wednesday 25
2 Sunday 20
3 Saturday 30

Using the above data source

SWITCH( A:A ,
       "Monday", "weekday",
       "Tuesday", UPPER(A:A),
       "Wednesday", B:B,
       "Thursday", "weekday",
       "Friday", "weekday",
       "Saturday", UPPER(A:A)) 
 

returns ("weekday", "TUESDAY", 25, "", "SATURDAY").

"Monday" is switched to "weekday",
"Tuesday" is switched to uppercase,
"Wednesday" is switched to its corresponding value in column B,
"Sunday" is switched to "" (null) because it does not match any case in the SWITCH function and
 "Saturday" is switched to uppercase. 

NOTE: specify _default_ to assign a default function to be performed if no other cases match.

SWITCH( A:A , 

       "Tuesday", UPPER(A:A),
       "Wednesday", B:B,
       "Saturday", UPPER(A:A),
       
"_default_", "weekday"

"Monday" is switched to "weekday",

"Tuesday" is switched to uppercase,
"Wednesday" is switched to its corresponding value in column B,
 "Saturday" is switched to uppercase and
all other days are switched to ""weekday" because they fall into the default case.

Related links: