Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join this live chat April 6, 10AM EST - QlikView to Qlik Sense REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
i_bagnoli
Creator
Creator

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
Partner
Partner

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

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?"

i_bagnoli
Creator
Creator
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

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
Partner
Partner

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

Not applicable

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

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