New to Qlik Sense

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

Announcements
Join us for a live Q&A! September 21, 10 AM ET - Onboarding Fast in Qlik Sense SaaS! REGISTER
cancel
Showing results for
Did you mean:
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)

• if statement

1 Solution

Accepted Solutions
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:
*,
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:

Jordy

Climber

Work smarter, not harder
3 Replies
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:
*,
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:

Jordy

Climber

Work smarter, not harder
Contributor
Author

Hi Jordy,

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?!

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
Tags
Community Browser