Switch (PQL)
Controls the flow of logic by executing certain statements if their 'case' matches the supplied input value.
- Returned Output: Variant
- Library: PQL \ Common \ Logical
- Version: 2020.12.000
- Compatibility:
- Can be combined with and other PQL function throughout the application.
- It CANNOT be used with MDX or VBA functions. But it can be used on MDX-based content in other parts of the application.
Syntax
* Click on the function's arguments above for more details on the input values.
Comments
- The Variable can be a numeric value, a String, or a Boolean. Its value can be derived from a data point (or tuple) or from a parameter.
- The Case values 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, String, or Boolean values (including data points and tuples), or to list or 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 (the Default) 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 typically return the same type of result: numeric, String, or Boolean values (and data points), or sets.
Different Function types
- See the implementation of Switch for semantic objects.
Examples
This example looks at the mathematical expression 4-2, and then looks at the various cases. The result is "bad", since it matches the 2.
Switch( 4-2, 1, “good”, 2, “bad”, “invalid” )