Databases Reference
In-Depth Information
Conditional functions
Often in QlikView, you want to modify the data based on a condition. For example,
we may want to classify any aircraft that was present in the database before 1990
as "Classic", and classify everything from 1990 onward as "Current". Let's open the
script editor and see how this is done:
1.
Locate the
[Aircraft Types] LOAD
statement.
2.
Add a comma behind the line
END_DATE as [Aircraft End Date]
and
press
Return
to create a new line.
3.
On the new line, put the following expression:
If(Year(BEGIN_DATE) <
1990, 'Classic', 'Current') as [Aircraft Age Classification]
4.
As the 2010 update only contains aircraft that are newer than 2010, we do not
need to use the conditional expression, instead we can use a fixed value.
5.
Add a comma behind the line
END_DATE as [Aircraft End Date]
and
press
Return
to create a new line.
6.
Put the following expression on this line:
'Current' as [Aircraft Age
Classification]
7.
Save
and reload the document.
8.
Add
Aircraft Age Classification
field to the
Aircraft
multibox.
When we select the value
Classic
from the
Aircraft Age Classification
drop-down
list, we see that only dates before the year 1990 are being selected.
The expression uses the
If
function as follows:
If(Year(BEGIN_DATE) < 1990, 'Classic', 'Current') as [Aircraft Age
Classification]
The
If
function takes three parameters:
• A condition, in our case
Year(BEGIN_DATE) < 1990
, which returns
true
if
the year of the date is before 1990. Otherwise false is returned
• The expression to use if the condition is
true
:
'Classic'
• The expression to use if the condition is
false
:
'Current'
As we will see later, QlikView has many other conditional functions. However,
the
If
function is the most common. For those who want to check the available
conditional functions, select
Help
|
Help
from the menu, choose the
Index
tab, and
search for
Conditional functions
.