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:
[Aircraft Types] LOAD
statement.END_DATE as [Aircraft End Date]
and press Return to create a new line.If(Year(BEGIN_DATE) < 1990, 'Classic', 'Current') as [Aircraft Age Classification]
END_DATE as [Aircraft End Date]
and press Return to create a new line.'Current' as [Aircraft Age Classification]
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:
Year(BEGIN_DATE) < 1990
, which returns true
if the year of the date is before 1990. Otherwise false is returnedtrue
: 'Classic'
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.