QlikView Expressor: The Decision Function

    Originally published on 07-21-2011 08:24 AM


    The decision function is included in the basic group of expressor datascript  functions.  This function can be used to create a single statement that  implements the same sort of processing as a case statement.  When you  use the decision function, you do not need to explicitly code a return  statement or an assignment statement.  Rather, the decision function  will return a value that you specify. Consequently, you can use the  decision function to implement the equivalent of a complex block of code  while adhering to the guidelines required of the Expression Editor.

    The API of the decision function sets up a series of logical comparisons, each associated with a return value.  The function evaluates each comparison in sequence and returns the return value for the first comparison that evaluates to true.

    As an example, let’s assume that each incoming record includes four attributes: the president’s chronological position, last name, first name, and party.  We want to rework the data in the input record, concatenating a president’s first and last names and identifying in which century he served.  Each outgoing record includes a single attribute named summary containing a statement such as “George Washington is an eighteenth century president.”  You could write expressor datascript to implement this logic but since a case statement is not part of the expressor datascript language, you would be forced to use an if..elseif..else block.

    But you could implement the same logic as a single statement, replacing the if..elseif..else block with the decision function.


    Note how the each comparison argument to the decision function performs the same logical discrimination as a case block within a case statement and that by using the decision function as an argument to the string.concatenate function, it is possible to generate the entire output value within a single statement.

    The code could also be entered into the Expression Rule as the syntax of the right-hand side of the assignment statement adheres to the guidelines for using an Expression Rule (the keyword return and assignment statements are not included in the coding).