Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

double comparison in one

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

1 Solution

Accepted Solutions
simenkg
Specialist
Specialist

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

View solution in original post

7 Replies
alexandros17
Partner - Champion III
Partner - Champion III

Si Irene,

definisci espressione nello script in questo modo:

let MyExpr =  espressione;

ed usa la variabile MyExpr nel tuo  if

mjayachandran
Creator II
Creator II

You mean in one line you want to have this expression?

or what  do you mean by "just one time?"

Anonymous
Not applicable
Author

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.

Not applicable
Author

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").

simenkg
Specialist
Specialist

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 applicable
Author

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 …

Not applicable
Author

if (expression between 30 and 60,...,...)