Skip to main content
Announcements
Qlik Community Office Hours - Bring your Ideation questions- May 15th, 11 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
salto
Specialist II
Specialist II

Compare the values of two numeric variables

Hello,

another (basic?) question:

I have Expr1 and Expr2 as two variables. I want to compare them:

=if(($(Expr1))>($(Expr2)),$(Expr1),$(Expr2))


But QV will no return anything.

The same happens if I use rangemax for this.

Is there any way to compare variables?


Regards.

12 Replies
kiranmanoharrode
Creator III
Creator III

Hi,

Try this, give this in number tab

=if(Num($(Expr1))>Num($(Expr2)),$(Expr1),$(Expr2))

Regards,

Kiran Rode

+91 8976977897

salto
Specialist II
Specialist II
Author

Hi Kiran,

thanks a lot for your fast answer,but the result still is a '-'

Is there a way to compare the values of two variables?

sundarakumar
Specialist II
Specialist II

What is the expression in $(Expr1) and $(Expr2),

and where are you using this if condition, in chart or script  or text box?

-Sundar

nilesh_gangurde
Partner - Specialist
Partner - Specialist

Try this:

=if((CHR(39)$(Expr1)CHR(39))>(CHR(39)$(Expr2)CHR(39)),CHR(39)$(Expr1)CHR(39),CHR(39)$(Expr2)CHR(39))



-Nilesh

salto
Specialist II
Specialist II
Author

Hello Sundar,

Expr1 and Expr 2 are document variables that have been set up like this:

Expr1:num(sum({<"Date"={"<=$(=date(DateID,'DD/MM/YYYY'))"}>} "Amount"))

Expr2:num(sum({<"Date"={"<=$(=date(DateID-30,'DD/MM/YYYY'))"}>} "Amount"))

And I was comparing them in  text box. The values for Expr1 and Expr2 were correctly shown in other two text boxes.

But I was not using exactly the syntax above for the variables and it seems to be the reason for them not to be correctly compared.

Now they are correctly evaluated and compared with rangemax or  with if(($(Expr1))>($(Expr2)),$(Expr1),$(Expr2))

Thanks a lot for your help!

salto
Specialist II
Specialist II
Author

Thanks Nilesh for your answer.

I have solved my issue with the above explanation.

Best regards,

nilesh_gangurde
Partner - Specialist
Partner - Specialist

Great

-Nilesh

Not applicable

Salto,

Do your Expr1 contain a numeric value ?

if yes, remove the $ expansion sign.

 

let v1=10;
let v2 = 100;


let v1E= 'v1';

let v2E= 'v2';

let v3 = if(v1 > V2, 2, 3);
let v3E = if($(v1E) > $(v2E), 2, 3);

Both v3 and v3E are = 3

Fabrice

nizamsha
Specialist II
Specialist II

Below these 2 any one will suits according to ur condition

=if($(vExpr1)>$(vExpr2),$(vExpr2),$(vExpr1))

=if('$(vExpr1)'>'$(vExpr2)',$(vExpr1),$(vExpr2) )