Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Problem with Variables


Hi

I have 2 variables: vTotOH and vTotOHBudget.  If I put $(vTotOH) in a text box I get 239.7 which is correct.  $(vTotOHBudget) gives 258.9 which is also correct.  But if I put $(vTotOH)-$(vTotOHBudget) I get 203.9 instead of -19.2.

vTotOH is defined as $(vStaff)+$(vEquip)+$(vOps)+$(vAdmin)+$(vCentral)

vTotOHBudget is very similar (5 other variables added together)

Thanks

1 Solution

Accepted Solutions
tresesco
MVP
MVP

This is a common mistake very often made while handling variables. Simple reason could be understood from the below explanation I hope: Say you define two variables like:

vVar1 -> Sum(A)+Sum(B)          // 10+5

vVar2 -> Sum(A)-Sum(C)           // 10-2

Now your expression =$(vVar1)*$(vVar2)    and you  expect

(15+5)*(10-2)

But  variable expansion actually makes it

15+5*10-2     

To avoid this confusion you can put '=' in the front of your variable declaration. Hope this helps and makes sense.

View solution in original post

6 Replies
avinashelite

Hi Adrian,

Can you please post your app.

Regards,

@vi

Not applicable
Author

Hi Adrain,

Can you please share the sample file

Not applicable
Author

Hi Adrian

Please try sum($(vStaff))+sum($(vEquip))+sum($(vOps))+sum($(vAdmin))+sum($(vCentral))

If you have null values and if you do not use sum it gives you different results

Thanks and regards

Padma

Anonymous
Not applicable
Author

I get Error in Expression error message if I try this

tresesco
MVP
MVP

This is a common mistake very often made while handling variables. Simple reason could be understood from the below explanation I hope: Say you define two variables like:

vVar1 -> Sum(A)+Sum(B)          // 10+5

vVar2 -> Sum(A)-Sum(C)           // 10-2

Now your expression =$(vVar1)*$(vVar2)    and you  expect

(15+5)*(10-2)

But  variable expansion actually makes it

15+5*10-2     

To avoid this confusion you can put '=' in the front of your variable declaration. Hope this helps and makes sense.

Anonymous
Not applicable
Author

That works!!

Thanks