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

If Statements

I need to write basically an elseif statement in an expression...

This works:


if(isnull($(vForecastVariance)), -1, $(vForecastVariance))

This doesn't:

=if(isnull(vForecastRound) and isnull(vActualRound),0, if(isnull($(vForecastVariance)), -1, $(vForecastVariance)))

I think it's a syntax error. Any suggestions?

Thanks!

Cassandra

1 Solution

Accepted Solutions
Not applicable

You may need something like this:

if ($(vForecastRound)=0 and ($(vActualRound))=0,0, if($(vForecastRound)=0, -1, $(vForecastVariance)))

Please see my test. keep loading and you can test different data set.

Thanks.

View solution in original post

10 Replies
sunny_talwar

I don't see any issue with the syntax. What is the error that you are seeing? May be its something to do with one of the variables you have in there.

cbaqir
Specialist II
Specialist II
Author

11-20-2015 12-00-15 PM.jpg

If Forecast and Actual are 0, Variance % should be 0%.

If Forecast is 0, Variance % should be -100%.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

When you reference vForecastVariance, you use the $() to evaluate it. For the other two variables you do not use $(). Are they constants?

Also not that 0 and null ar different. That ifNull(0) = false.

-Rob

maxgro
MVP
MVP

if(sum(forecast)=0 and sum(actual)=0,

  0,

  sum(forecast) / sum(actual) -1

  )

1.png

cbaqir
Specialist II
Specialist II
Author

I updated all variables to use $() but it did not change the end result.

If vForecastRound and vActualRound are 0, I want the expression to show 0 (which would show 0%).

cbaqir
Specialist II
Specialist II
Author

There are 2 if statements to merge:

if ($(vForecastRound)=0 and ($(vActualRound))=0,-1, $(vForecastVariance))

or

if($(vForecastVariance))=0, 0, $(vForecastVariance)))

tamilarasu
Champion
Champion

Hi Cassandra,

Could you split the statement and do a test whether the results are fine or not.

=if(($(vForecastRound)=0 and $(vActualRound)=0),0,1)


=if($(vForecastVariance)=0, -1, $(vForecastVariance))


Also add expressions for the variables =$(vForecastRound), =$(vActualRound) and =$(vForecastVariance). So that you can see where you have the problem.


If both works correctly, then the below should work.


=if(($(vForecastRound)=0 and $(vActualRound)=0),0,if($(vForecastVariance)=0, -1, $(vForecastVariance)))

cbaqir
Specialist II
Specialist II
Author

11-23-2015 12-49-42 PM.jpg

If Forecast is 0, Variance % should be -100%.

In the case of the first line, I would expect Variance to be -100%.

=if(($(vForecastRound)=0 and $(vActualRound)=0),0,1)  = 1


=if($(vForecastVariance)=0, -1, $(vForecastVariance)) = 0

Not applicable

You may need something like this:

if ($(vForecastRound)=0 and ($(vActualRound))=0,0, if($(vForecastRound)=0, -1, $(vForecastVariance)))

Please see my test. keep loading and you can test different data set.

Thanks.