Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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
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'
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?
Try
IF(([Success Percentage] >= .76), 1, 0) AS '76-100'
IF(([Success Percentage] =< .75) AND ([Success Percentage] >= .51), 1, 0)) AS '51-75'
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
];
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
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?
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
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
Huzzah! Thank you all.