Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to use if-statement in Qlikview?

Hi

I am using in excel very often formula if(iserror(.... How could I use that in Qlikview?

I have a problem that sometimes I don't get any result with my formula because some part is missing and in these cases I would like to use another formula. How can I write that script?

I have following script

=if(Sum(demand*price)=0,Sum(demand*([Beginning Inventory]/[Beginning Inventory kg])),Sum(demand*price))

0 is wrong in this formula.

If price doesn't exist I will not get any result.

In excel I would write this as following

If(iserror(demand*price),([Beginning Inventory]/[Beginning Inventory kg])*demand,(demand*price))

How can I do same thing in QlikView??

Thanks

Janne

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

=if(Sum(demand* Alt(price, 0))=0,Sum(demand*([Beginning Inventory]/[Beginning Inventory kg])),Sum(demand*price))

If Price is null, Alt() will return 0.

Hope this helps you.

Regards,

Jagan.

View solution in original post

5 Replies
nilesh_gangurde
Partner - Specialist
Partner - Specialist

use the below mentioned script :

=if(isnull(price),Sum(demand*([Beginning Inventory]/[Beginning Inventory kg])),Sum(demand*price))

you can use the isnull() function to find out that the "Price" exist or not. and accordingly calculate the results.

-Nilesh

m_woolf
Master II
Master II

I can't think of a reason that demand*price would produce and error, except that demand might be null.

Try: if(isnull(demand), .....

or maybe

if(len(demand)=0, ....

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

=if(Sum(demand* Alt(price, 0))=0,Sum(demand*([Beginning Inventory]/[Beginning Inventory kg])),Sum(demand*price))

If Price is null, Alt() will return 0.

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

Hi

Thanks! the "Alt" function was excatly what I needed.

Many thanks

Janne

Not applicable
Author

Hi

Once again thanks for your great advice. However I have now another problem. QlikView doesn't sum this formula properly in my pivot chart.

I have now following formula monster there

if(Sum(demand*alt(price,0))=0,if(sum(demand*alt(average,0))=0,if(alt(demand,0)=0,0,demand),(sum(demand)*average)),Sum(demand*price))

This formula returns values in every case, but in total row the sum is wrong. If I take all values in to excel I can see that total is something else than Qlikview is telling me. How should I modify my formula that the total sum would be calculated in a right way?

Thanks

Regards

Janne