Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi community,
is it possible to obtain a result like that:
if(
expression >30
and
expression<60
,1,0)
using "expression" just one time?
Thanks
IB
It is best practice to put your expressions in variables.
for instance:
if you have the evaluation
if(sum({$<Year={'2014'},Sector={Finance},SomeFlag={1},SomeOtherFlag={0}>}Amount)>30
and
sum({$<Year={'2014'},Sector={Finance},SomeFlag={1},SomeOtherFlag={0}>}Amount)<60
,1,0)
Go to your variable overview: Settings - Variable Overview. Press Add and give it a name: vExpression. Scroll down to it and select it. In the "Definition" field you write:
sum({$<Year={'2014'},Sector={Finance},SomeFlag={1},SomeOtherFlag={0}>}Amount)
Then the evaluation becomes:
if($(vExpression)>30 and $(vExpression)<60,1,0)
Hope this helps
SKG
Si Irene,
definisci espressione nello script in questo modo:
let MyExpr = espressione;
ed usa la variabile MyExpr nel tuo if
You mean in one line you want to have this expression?
or what do you mean by "just one time?"
I mean, I would like to use "expression" only one time. This need comes from the fact that the expression I'm talking about is too long and complicated and qlik doesn't work well.
You should copy and paste that expression between ( ) and then add the > 30, an 'AND' and again the expression with the 2do condition. Or use a variable and put that expression in it, and again: the both conditions with the expression, separated with an 'AND'.
If you are asking to use just 1 time the expression like this:
30 < expression < 60
You can't. Unless a function provides it (in this case should be something like a "between").
It is best practice to put your expressions in variables.
for instance:
if you have the evaluation
if(sum({$<Year={'2014'},Sector={Finance},SomeFlag={1},SomeOtherFlag={0}>}Amount)>30
and
sum({$<Year={'2014'},Sector={Finance},SomeFlag={1},SomeOtherFlag={0}>}Amount)<60
,1,0)
Go to your variable overview: Settings - Variable Overview. Press Add and give it a name: vExpression. Scroll down to it and select it. In the "Definition" field you write:
sum({$<Year={'2014'},Sector={Finance},SomeFlag={1},SomeOtherFlag={0}>}Amount)
Then the evaluation becomes:
if($(vExpression)>30 and $(vExpression)<60,1,0)
Hope this helps
SKG
Not completely sure if this addresses your question, but you can define the expression in the script area and then call it later using dollar sign expansion:
LET expression = 5 + 30;
If $(expression) > 30 Then …
if (expression between 30 and 60,...,...)