Qlik Community

Ask a Question

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
Become an analytics expert with Qlik's new 15 week course: Applied Data Analytics using Qlik Sense. READ MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Matthias1
Contributor
Contributor

Dual IF Funtion

Hi,

Quick question. I want to define a "Morning Peak" and an "Afternoon Peak" from 7 AM to 9 AM respectively 15 AM to 17 AM.

If(Hour(PlanDepTime)>=7 AND Hour(PlanDepTime)=<9,'MorningPeak',If(Hour(PlanDepTime)>=15 AND Hour(PlanDepTime)=<18,'AfternoonPeak','NoPeak')

The format of PlanDepTime is hh:mm:ss

But in the code QlikSense does not read the AND as a Function and therefore does not except the formula.
What am I doing wrong here?

 

Thank you very much for your help
Matthias

Labels (2)
1 Solution

Accepted Solutions
JordyWegman
Partner
Partner

Hi Matthias,

I think you missed a ')' at the end of your formula and that is why it is not working.

Take this example:

Table:
Load
	*,
    If(Hour(time)>=7 and hour(time)<=9,'Morning peak',IF(Hour(time)>=15 and hour(time)<=18,'Afternoon peak','No peak')) as Category
   ;
Load * Inline [
ID, time,
1, 07:37:15
2, 13:13:51
3, 17:23:45
];

This is the outcome:2019-03-20 21_19_23-Window.png

Jordy

Climber

Work smarter, not harder

View solution in original post

3 Replies
JordyWegman
Partner
Partner

Hi Matthias,

I think you missed a ')' at the end of your formula and that is why it is not working.

Take this example:

Table:
Load
	*,
    If(Hour(time)>=7 and hour(time)<=9,'Morning peak',IF(Hour(time)>=15 and hour(time)<=18,'Afternoon peak','No peak')) as Category
   ;
Load * Inline [
ID, time,
1, 07:37:15
2, 13:13:51
3, 17:23:45
];

This is the outcome:2019-03-20 21_19_23-Window.png

Jordy

Climber

Work smarter, not harder

View solution in original post

Matthias1
Contributor
Contributor
Author

Hi Jordy,

thank you for your reply.

Your were right, but even when adding the 1 missing right parenthesis it still tells me that there is one missing. I can add another 3 parenthesis and it still tells me the that there is a right parenthesis missing?!

JordyWegman
Partner
Partner

Hi Matthias,

I would advice you to do this in the back-end (read script). This is easier because you can then add this as a dimension itself.

Copy my formula and fill in 'PlanDepTime' instead of 'time'.

If you are still planning of doing this in the front-end, create a measure (not dimension!) and copy my formula and fill in 'PlanDepTime' instead of 'time'. This should also work.

Jordy 

Climber

Work smarter, not harder