Databases Reference
In-Depth Information
Conditional functions
There are several conditional functions in QlikView that can be used in the frontend
to give our charts a higher level of flexibility in terms of handling and presenting the
data, both in expressions and dimensions. Let's go through some examples of these
functions to enhance the analysis in our QlikView app.
The If function
Though sometimes neglected because of its high resource usage when compared
to other methods (such as Set Analysis, which is covered in the next chapter), the
If
function has important uses when creating QlikView documents. Essentially, it
is used when two or more different outputs should result from a single expression,
depending on a condition that is evaluated to either be
true
or
false
.
In this section, we'll explain how it works and discuss a use case.
The syntax
As the first step, we should describe the syntax used by this function and the
parameters it needs to work. If you've worked with Microsoft Excel previously,
then it's very likely you well have come across the
If
function in a spreadsheet.
The syntax of the
If
function in QlikView is almost the same as that in Excel.
The function takes the following three parameters:
•
Condition
: An expression that, when evaluated, results in either
true
or
false
. Relational and logical operators are used to create the expression.
•
Then
: The expression or value set as the
then
parameter will be the output of
the
If
function whenever the condition results in
true
.
•
Else
: The expression or value set as the
else
parameter will be the output of
the
If
function whenever the condition results in
false
.
The pseudocode is:
if(condition , then , else)
The
If
function can also be used as a script function for creating calculated fields.
The syntax would be the same.
Additionally, a nested
If
expression can be constructed in the following manner:
If(condition1, expr1,
If(condition2, expr2,
expr3))