Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

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.

Tags (2)
1 Solution

Accepted Solutions
Employee
Employee

Re: If Statement with And Opperator

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
9 Replies
qvelhoff
Valued Contributor

Re: If Statement with And Opperator

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

Re: If Statement with And Opperator

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?

qvelhoff
Valued Contributor

Re: If Statement with And Opperator

Try

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

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

MVP
MVP

Re: If Statement with And Opperator

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

];

Employee
Employee

Re: If Statement with And Opperator

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

Re: If Statement with And Opperator

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

Employee
Employee

Re: If Statement with And Opperator

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
Employee
Employee

Re: If Statement with And Opperator

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
Not applicable

Re: If Statement with And Opperator

Huzzah! Thank you all.

Community Browser