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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
bwisealiahmad
Partner - Specialist
Partner - Specialist

Nested IF only work on first condition

Trying to use a Variable to change sheets when a timer hits a certain amount of seconds. Written this IF statement which comes out "ok" as an expression, but only the first condition works. The 0 or 1. Not the condition for 2, 3, 4, 5 etc. Any ideas? Probably something simple I've overlooked.

=

if(vTimerSec >= 5, 1,

if(vTimerSec >= 10, 2,
if(vTimerSec >= 15, 3,
if(vTimerSec >= 25, 4,
if(vTimerSec >= 35, 5

,0)))))

1 Solution

Accepted Solutions
Colin-Albert
Partner - Champion
Partner - Champion

Try

If (vTimerSec >= 35, 5,

If (vTimerSec >= 25, 4,

If (vTimerSec >= 15, 3,

If (vTimerSec >= 10, 2,

If (vTimerSec >= 5, 1,

0))))) ;

View solution in original post

7 Replies
Colin-Albert
Partner - Champion
Partner - Champion

All of the conditions you have listed are > 5, so only the first line is actioned.

Anonymous
Not applicable

It works as supposed, because >=10 is also >=5 and so on...

Colin-Albert
Partner - Champion
Partner - Champion

Try

If (vTimerSec >= 35, 5,

If (vTimerSec >= 25, 4,

If (vTimerSec >= 15, 3,

If (vTimerSec >= 10, 2,

If (vTimerSec >= 5, 1,

0))))) ;

Chanty4u
MVP
MVP

try ascending order ...he ranges 35 to 5

Not applicable

Hi Ali,

Can you please try below and let me know if it works.

if(vTimerSec >= 5 and vTimerSec < 10, 1,

    if(vTimerSec >= 10 and vTimerSec < 15, 2,

    if(vTimerSec >= 15 and vTimerSec < 25, 3,

    if(vTimerSec >= 25 and vTimerSec < 35, 4,

    if(vTimerSec >= 35, 5

,0)))))

Thanks,
Sreeman.

Colin-Albert
Partner - Champion
Partner - Champion

That will work, but if you apply the test against the largest value first and the rest in descending order you only need to test for one condition on each row not two tests.

bwisealiahmad
Partner - Specialist
Partner - Specialist
Author

Thanks for the help Colin and Sreeman! Really appreciate it. Such a easy twist to it made it work