3.5.10.7 Switch

Description

Minimum Origin Version Required: 2019 SR0

This function is used to compare a value expression to a set of values val. If match is found, return the corresponding res. Up to 39 comparing values are supported. If no match is found, default value will be returned.

Syntax

string switch(string expression, double val1, string res1$[, double val2, string res2$]...[, double val39, string res39$][,string default$])$
double switch(string expression, double val1, double res1[, double val2, double res2]...[, double val39, double res39][, double default])

Parameters

expression

The value to be comparied.

valn

The value to be comparied with expression to see if matches. Can be numeric or text. If text value, must be inclosed in double quotes ("").Up to 39 values can be supported.

resn

The returned value when valn match is found. Can be numeric or text. If text value, must be inclosed in double quotes (""). Up to 39 values are supported

default

Optional. The default value when no match is found. Can be numeric or text. If text value, must be inclosed in double quotes ("").

Return

Return value res when the corresponding value val is found in expression.

Example

Ex1

IF value in col(A) is Apple, returns Fruit, if Boy, returns People, if Cat returns Animal.

  1. Create a new Workbook. Fill col(A) with Apple, Boy, and Cat randomly.
  2. Right click on col(B) and select Set Column Values from context menu. In the Set Values dialog enter formula
    switch(A$,"Apple","Fruit","Boy","People","Other")$

See Also

If, Ifs