Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Ragnar
Contributor II
Contributor II

If statement not working

Hi Community,

I'm trying to figure out why my 2nd half of my if expression isn't working. First half produces the value as expected.

Context is - Marketing Preferences

If a user ticks Marketing Opt Out then the salesman can't contact the customer via phone, email, mail and fax. 

 

I have the first half IF expression working - =if(mail_opt_out=-1, do_not_email=0,'No') - works for phone, fax, mail too.

Ragnar_1-1638442826369.png

When I add a 2nd IF so that if Marketing Opt Out isn't ticked then the salesman can contact the customer via phone, mail, email or fax and it gets OKAYED by qliksense.

=if(mail_opt_out=-1, do_not_email=0,'No') OR If(mail_opt_out=0, do_not_email=-1,'Yes')

Ragnar_2-1638442985540.png

When I check the results the email column, it turns the column cells into Nulls and that bottom x3 rows should be presenting Yes and top two rows as NO which make sense based off the expression.

Ragnar_0-1638442587302.png

Any thoughts, please? 

 

 

 

As I was typing this, I thought of another caveat, because for example, if a customer only ticks Email as a contact preference but no to mail, phone & fax then this IF expression wouldn't encapsulate that. 

I have specified what the Yes & No values are (-1 = Yes and 0-No) in the load script

Ragnar_3-1638443527103.png

I got a feeling I need to do this in load in order to bypass the caveat. I hope I made sense.

Any insight is appreciated and have a pleasant day community.

Thanks for your time.

 

2 Replies
Or
MVP
MVP

Your entire condition doesn't seem to be in Qlik syntax unless you're intentionally writing it in a rather odd way. Assuming I'm parsing what you want correctly, it should be something like:

=if(mail_opt_out=-1 AND do_not_email=0,'No', If(mail_opt_out=0 AND do_not_email=-1,'Yes'))

The syntax for If() is If(Condition , Then, Else) and in your case, it looks like you're separating multiple conditions by a comma instead (which means the second condition is actually being evaluated as the Then / True expression, and the expected result for both conditions is being evaluated as the Else / False).

 

Ragnar
Contributor II
Contributor II
Author

Hi Or,

 

Thank you for your response, its appreciated. Unfortunately, it still produced empty fields, and turns out that the issue resided in our CRM system - needed to rename the marketing preferences so it then pulls the correct value through without having to script any front end expressions. Kept the if expressions as show in the photo above and it worked.

 

Once again thanks for your time.