Switch (PQL)

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

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

Syntax

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

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

Comments
  • Variable: The argument should be a simple value, a column, or another function.
  • Case: The argument should represent an outcome or value that the variable will be checked against.
  • Statement: The argument represents the resolved value or column that will be returned if the case is EQUAL to the variable.
  • Case N and Statement N: means you can add as many case-statement pairs as needed to the function (from 1 to "n").
  • Default: This optional argument represents the result where all cases are inapplicable (false).
  • For details on how to employ and use this function see the custom column overview.
Different Function types
  • This function is similar to the PQL semantic and common functions of the same name. However, it operates on a column directly at the grain.
  • It is also similar to the more advanced CASE function.
  • As a granular function, it is used in the base SQL query itself.

Example

This example checks the quantity column and resolves to different text values based on which values the quantity values match.

Switch( [transactions].[Quantity], 1, "one", 2, "two", "something" )

You can see the effect from this example snippet in the switch column at position #7, based on the quantity column in position #1.