Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If then expressions

I am trying to do an "if then" expression but have not done one in qlikview before

I currently have the following expression to calculate sales volume variance:

(Sum( {$<Year={$(=Max(Year))}>} Tons) - Sum( {$<Year={$(=Max(Year))}>} PlanTons))*(Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales)/Sum( {$<Year={$(=Max(Year))}>} PlanTons))

I want to create an "if then" that if the above expression = 0, to then display an amount = Sum( {$<Year={$(=Max(Year))}>} BaseSales)

but it keeps bombing out on me.

Can anyone help?

Thanks

1 Solution

Accepted Solutions
sasiparupudi1
Master III
Master III

If((Sum( {$<Year={$(=Max(Year))}>} Tons) - Sum( {$<Year={$(=Max(Year))}>} PlanTons))*(Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales))=0,

Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales) ,

(Sum( {$<Year={$(=Max(Year))}>} Tons) - Sum( {$<Year={$(=Max(Year))}>} PlanTons))*(Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales)/Sum( {$<Year={$(=Max(Year))}>} PlanTons))

)

View solution in original post

7 Replies
vishsaggi
Champion III
Champion III

Try this?

= IF(((Sum( {$<Year={$(=Max(Year))}>} Tons) -

      Sum( {$<Year={$(=Max(Year))}>} PlanTons)) * (Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales)/Sum( {$<Year={$(=Max(Year))}>} PlanTons))) = 0,

      Sum( {$<Year={$(=Max(Year))}>} BaseSales))

Not applicable
Author

still giving me no values:

failed if statement.PNG

vishsaggi
Champion III
Champion III

What is your expected output? Can you share a sample app ?

tyagishaila
Specialist
Specialist

Suppose expression below has Label Exp

(Sum( {$<Year={$(=Max(Year))}>} Tons) - Sum( {$<Year={$(=Max(Year))}>} PlanTons))*(Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales)/Sum( {$<Year={$(=Max(Year))}>} PlanTons))


now add expression

if(Exp=0,Sum( {$<Year={$(=Max(Year))}>} BaseSales), Exp)


and hide column Exp in presentation Tab.

jonathandienst
Partner - Champion III
Partner - Champion III

Rephrasing your requirements, if the first two terms are the same (resulting in 0 for the first expression):

If(Sum({$<Year = {$(=Max(Year))}>} Tons) <> Sum( {$<Year = {$(=Max(Year))}>} PlanTons),

  (Sum({$<Year = {$(=Max(Year))}>} Tons) - Sum( {$<Year = {$(=Max(Year))}>} PlanTons))

  * (Sum({$<Year = {$(=Max(Year))}>} PlanBaseSales) / Sum({$<Year = {$(=Max(Year))}>} PlanTons)),

  Sum({$<Year={$(=Max(Year))}>} BaseSales)

)

That simplifies the problem and reduces the calculation, but does not cover the case where PlanBaseSales = 0. If that needs to be considered as well, you will probably need the whole expression in the If condition. In psuedo-code:


If(<expression 1> <> 0, <expression 1>, <expression 2>)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
sasiparupudi1
Master III
Master III

If((Sum( {$<Year={$(=Max(Year))}>} Tons) - Sum( {$<Year={$(=Max(Year))}>} PlanTons))*(Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales))=0,

Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales) ,

(Sum( {$<Year={$(=Max(Year))}>} Tons) - Sum( {$<Year={$(=Max(Year))}>} PlanTons))*(Sum( {$<Year={$(=Max(Year))}>} PlanBaseSales)/Sum( {$<Year={$(=Max(Year))}>} PlanTons))

)

Not applicable
Author

thank you