Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Nested IF Statement

Is it possible to nest an IF statement within another IF statement? So for example for the below... would that be the best way of doing things?


If(Len(NetSalesValue) > 9, 0, NetSalesValue)  as [Invoice Value],

if(NetSalesValue < 0, NetSalesValue, 0) as [Credit Value],

I would like to still apply the Invoice Value IF to the Credit Value.

Tags (2)
1 Solution

Accepted Solutions
MVP
MVP

Re: Nested IF Statement

Hi Lewis,

Yes, that's possible indeed and should work just fine in the script. Check this syntax:

If(

  If(Len(NetSalesValue) > 9, 0,NetSalesValue) < 0,

    NetSalesValue, 0) as [Credit Value],

Hope that helps.

Miguel

3 Replies
MVP
MVP

Re: Nested IF Statement

Hi Lewis,

Yes, that's possible indeed and should work just fine in the script. Check this syntax:

If(

  If(Len(NetSalesValue) > 9, 0,NetSalesValue) < 0,

    NetSalesValue, 0) as [Credit Value],

Hope that helps.

Miguel

Not applicable

Re: Nested IF Statement

I think the problem you have is that you have called the NetSalesValue twice... try the formula below..

if(If(Len(NetSalesValue) > 9, 0, NetSalesValue)< 0, NetSalesValue, 0) as [Credit Value],

Or you could use this.

If(Len(netSalesValue)>9 and NetSalesValue<0, NetSalesValue,0) as [Credit Value],

I Hope this helps

Ali

Not applicable

Re: Nested IF Statement

Thanks again Miguel, thats perfect and works a treat!

Community Browser