Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

If / And Syntax

Hi I have the following if statement (which works fine ) :

If (Status like 'Approved*' ,'qmem://<bundled>/BuiltIn/led_g.png',         // If Status 'approved' then green led

     If (Status like 'Pending*','qmem://<bundled>/BuiltIn/led_r.png',         // If Status 'pending' then red led

       'qmem://<bundled>/BuiltIn/led_y.png')) as Invoice_Status              // otherwise yellow led

However If add an ADD statement using a field in the same table it seems I am missing brackets somewhere and my syntax is incorrect (?)

If (Status like 'Approved*' AND Invoice like 'Paid*','qmem://<bundled>/BuiltIn/led_g.png', // If Status 'approved' AND invoice 'paid' then                                                                                                                                           green led

               If (Status like 'Pending*','qmem://<bundled>/BuiltIn/led_r.png',                        // If Status 'pending' then red led

                  'qmem://<bundled>/BuiltIn/led_y.png')) as Invoice_Status                            // otherwise yellow led

Can anyone assist in spotting the mistake(s) in my syntax ?

Thanks

4 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Make sure you're using exact case sensitive values. Invoice is not the same field as invoice. And 'Paid' is not 'paid'.


talk is cheap, supply exceeds demand
Anonymous
Not applicable
Author

Hi Gysbert, I've checked that and they are the exact same values. As mentioned the first statement works but as soon as I add an 'and' statement it highlights the brackets as if to say there is a bracket missing elsewhere.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Can you please close your earlier discussion If statement format?

BTW how do you know that this code is wrong? Does the script engine complain? Do you get NULL values? Does the code always return the default value (last parameter)?

Peter_Cammaert
Partner - Champion III
Partner - Champion III

I don't know the order of precedence of logical operators by heart, but you can try adding more parentheses to separate the components of the logical expression, like in:

If ((Status like 'Approved*') AND (Invoice like 'Paid*'), 'qmem://<bundled>/BuiltIn/led_g.png',