Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.


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.

Not applicable

Problem with If instruction

Dear all,

I'm becaming crazy. How don't understand where is my mistake

IF (sum({<MY_YEAR={$(=Only(MY_ANNO-1))}>} MY_SALES) = 0,1, MY_MARGIN/sum({<MY_YEAR={$(=Only(MY_ANNO-1))}>} MY_SALES))

By the script above, I would obtain the following scenario:

if sum( ..... MY_SALES) = 0 , put MY_MARGIN = 1, else do the margin calculation.

But it doesn't work

Help please

Thanks in advance

2 Replies
Not applicable

Re: Problem with If instruction

I don't see anything wrong with it. If you select a value for MY_ANNO then you should get a result as long as there is data where MY_YEAR = MY_ANNO - 1

talk is cheap, supply exceeds demand
Not applicable

Re: Problem with If instruction

Without knowing your data structure, I guess you should add some operation to MY_MARGIN field except it returns one value only. Otherwise you cannot divide an array of possible values by a unique SUM() of any other field.

Also, try using the ONLY() function with just the field as parameter, keeping the "-1" outside.

Let us know if the following expression works fine:

IF (SUM({<MY_YEAR={$(=ONLY(MY_ANNO)-1)}>} MY_SALES) = 0,