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
Join us March 10th, 7 Ways Modern Analytics Can Help You Take Smarter Action. REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If Statement with And Opperator

Hi,

I'm trying to include an AND operator in my IF statement, but I'm getting the error: ')' expected from the below bit of script. The first line works perfectly and is just an example of what I'm trying to do.

IF("Success Percentage" >= .76, 1, 0) AS '76-100',

    IF("Success Percentage" =< .75 AND "Success Percentage" >= .51, 1, 0) AS '51-75'

I'd be grateful for any assistance.

1 Solution

Accepted Solutions
Michael_Tarallo
Employee
Employee

Got it

You have =< instead of <=

Please mark the appropriate replies as CORRECT / HELPFUL so our team and other members know that your question(s) has been answered to your satisfaction.

Regards,

Mike Tarallo

Qlik

Regards,
Mike Tarallo
Qlik

View solution in original post

9 Replies
NickHoff
Specialist
Specialist

Qlikview was interpreting your nested if statement as 1 statement and you had two different alliases in one statement.  You are better off creating the indicator in two different fields.

IF([Success Percentage] >= .76, 1, 0) AS '76-100'

IF([Success Percentage] =< .75 AND [Success Percentage] >= .51, 1, 0) AS '51-75'

Not applicable

Apologies for the confusion - my script was not intended to be a nested if statement. I meant to have two different fields.

I ran what you provided:

IF([Success Percentage] >= .76, 1, 0) AS '76-100'

IF([Success Percentage] =< .75 AND [Success Percentage] >= .51, 1, 0) AS '51-75'

And, I'm experiencing the same error. Any ideas?

NickHoff
Specialist
Specialist

Try

IF(([Success Percentage] >= .76), 1, 0) AS '76-100'

IF(([Success Percentage] =< .75) AND ([Success Percentage] >= .51), 1, 0)) AS '51-75'

maxgro
MVP
MVP

1.png

load

[Success Percentage],

IF([Success Percentage] >= .76, 1, 0) AS '76-100',

IF([Success Percentage] <= .75 AND [Success Percentage] >= .51, 1, 0) AS '51-75';

load * inline [

Success Percentage

0.32

0.6

0.7

0.8

];

Michael_Tarallo
Employee
Employee

Hi Brenna - Nick's suggestion is correct if you are using this in the Load Script, for both QlikView and Qlik Sense. The AS keyword allows you to alias the expression as a field value and will then be part of the data model.

- but if you are using Qlik Sense you might also find these videos helpful - as they show you to define the script in reusable objects - measures and dimensions within the Master Items list.

More videos here: New to Qlik Sense Videos

Let us know how you do.

Please mark the appropriate replies as CORRECT / HELPFUL so our team and other members know that your question(s) has been answered to your satisfaction.

Regards,

Mike Tarallo

Qlik

Regards,
Mike Tarallo
Qlik
Not applicable

Thank you all!

Though It appears that neither of Nick's suggestions will work for me. The first line with the field '76-100' works perfectly, but the second does not. Are AND operators allowed in IF in Qlik Sense?

qliksense community help.PNG

Michael_Tarallo
Employee
Employee

Hi Brenna,

See attached .qvf - this does work for me in my version of Qlik Sense Desktop 1.1

copy to C:\Users\<user profile>\Documents\Qlik\Sense\Apps refresh the Desktop (F5)

-----------------

Load

[Success Percentage],

IF(([Success Percentage] >= .76), 1, 0) AS '76-100',

IF(([Success Percentage] <= .75) AND ([Success Percentage] >= .51), 1, 0) AS '51-75';

load * inline [

Success Percentage

0.32

0.6

0.7

0.8

];

Is it possible your error is coming from somewhere else in the script?

Please mark the appropriate replies as CORRECT / HELPFUL so our team and other members know that your question(s) has been answered to your satisfaction.

Regards,

Mike Tarallo

Qlik

Regards,
Mike Tarallo
Qlik
Michael_Tarallo
Employee
Employee

Got it

You have =< instead of <=

Please mark the appropriate replies as CORRECT / HELPFUL so our team and other members know that your question(s) has been answered to your satisfaction.

Regards,

Mike Tarallo

Qlik

Regards,
Mike Tarallo
Qlik

View solution in original post

Not applicable

Huzzah! Thank you all.