switch

Description

With switch, you can list a set of values that can be assigned to an expression. Which expression gets used as output, is determined by how you write the switch-expression.

The expression has to close with the keyword end.

This operator is most often used in calculated information.

Syntax

switch [expression]
when [value_1] then [expression_1]
...
when [value_n] then [expression_n]
else [expression]
end
  • All values will be compared against the result of the expression

  • All expressions need to return the same type of output, e.g. a number.

  • If none of the defined values apply, the expression following else is used.

Example

A Zurich-based institution is mostly active in its home market and in Germany. It groups its customers in three categories, based on where they live.

Swiss customers get labeled as local. German customers get the label German. The relatively small number of customers from other countries get grouped together in a ‘world’ category.

switch self.domicile
when che then local_customer
when deu then german_customer
else world_customer
end

If the domicile of the instance is provided as Germany, the output will mark the instance as german_customer. Is the domicile South Africa, the else is used: this instance is ‘world_customer’.