Switch (PQL)

Controls the flow of logic by executing certain statements if their 'case' matches the supplied input value.

  • Returned Output: Variant
  • Library: PQL \ Semantic \ Logical
  • Version: 2018.00.000
  • Compatibility: Pyramid Query Language (PQL) data sources


Switch( <Variable> , <Case N> , <Statement N> , OPTIONAL <Default> )

* Click on the function's arguments above for more details on the input values.

  • The variable must be a numeric value derived from a data point (or tuple), or from a parameter.
  • The case values (1 to 'n') need to be numeric and are compared to the variable value provided.
  • A statement or expression is required for each case value (separated by a comma).
    • The statements can evaluate to numeric values (including data points and tuples), or to list/ set definitions for producing a list of model elements from a hierarchy.
    • If the expression results are list or set definitions, the final resolved element list must come from the same model hierarchy.
  • The last statement is optional and does not need a case value. It will be the default expression if no cases match the variable.
  • The statement expressions should return the same type of result: either numeric values (and data points), or sets. Mixing result types can lead to errors.
  • For details on how to employ and use this function see the semantic calculation overview.
Different Function types
  • The common library offers a similar "CASE" function for non-model operations. See this function.
  • The IF function is also similar to 'Switch'.


This example looks at the quantity of blade products. If it is 100, it returns a list of countries - Australia, US and Canada. If it is 200, it returns a list of countries - France and Germany. Otherwise, it returns a list of countries - UK and Finland:

Switch( ([measures].[Quantity],[Product].[Product].[Blade]) 100, {[Customer].[Country].[Australia], [Customer].[Country].[United States], [Customer].[Country].[Canada]}, 200, {[Customer].[Country].[France], [Customer].[Country].[Germany}, {[Customer].[Country].[United Kingdom], [Customer].[Country].[Finland} )

This examples looks at the value of an input parameter called variable "v1". If v1 is 1, it returns the values of sales plus 10%. If v2 is 2, it returns the values of sales plus 25%. Otherwise, it returns the value of sales minus net profit:

Switch( [variable].#[v1], 1, [measures].[sales] * 1.10, 2, [measures].[sales] * 1.25, [measures].[sales] - [measures].[net profit] )