Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

bwisealiahmad
Valued Contributor

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

Re: Nested IF only work on first condition

Try

If (vTimerSec >= 35, 5,

If (vTimerSec >= 25, 4,

If (vTimerSec >= 15, 3,

If (vTimerSec >= 10, 2,

If (vTimerSec >= 5, 1,

0))))) ;

7 Replies

Re: Nested IF only work on first condition

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

robin_hausdoerfer
Valued Contributor III

Re: Nested IF only work on first condition

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

Re: Nested IF only work on first condition

Try

If (vTimerSec >= 35, 5,

If (vTimerSec >= 25, 4,

If (vTimerSec >= 15, 3,

If (vTimerSec >= 10, 2,

If (vTimerSec >= 5, 1,

0))))) ;

Chanty4u
Esteemed Contributor III

Re: Nested IF only work on first condition

try ascending order ...he ranges 35 to 5

Not applicable

Re: Nested IF only work on first condition

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.

Re: Nested IF only work on first condition

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
Valued Contributor

Re: Nested IF only work on first condition

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