Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problems with defined variables

This a general question because it happen sometimes and I don't know how and why it happens.

Here is the question:

Suppose you define 2 variables v1 and v2 using the input box.

There are times when you type in ($(v1)) / ($(v2)) [That's v1 divided by v2] as an expression in a chart, there is no result.

But if you type try to replace one of the variables with the actual formula, then it works.

(e.g. let's say v2 = formula2. Then if I change the expression to $(v1)/(formula2) it will work.

I am sorry if this question is not clearly stated.

Just wondering if anyone have similar problem before?

4 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I'm not sure on your specific example without knowing the content of your variables, but here's a general explanation that may help you understand.

The $() causes the variable to be evaluated before substitution. So

  $(v1)) / ($(v2)

means the result of v1 divided by the result of v2. By contrast

  v1 / v2

means the contents (as a string) of v1 divided by the contents of v2.  So a chart dimension X with a value of 6 and:

  v1 = 2

  v2 = X * 2

$(v1) + $(v2)  =  2 + 6 * 2  =   14

v1 + v2   =  2 + 'X' * 2  = null

v1 + $(v2)  =  2 + 6 * 2  =   14

I know it doesn't quite explain your particular example, maybe you can post some example variables.

-Rob

Not applicable
Author

I tried to reproduce your concern, but was not able to. Can you share a specific scenario in which you came across this.?

Thanks,

Angad

Not applicable
Author

Thanks everyone.

I face similar situation today. And I found that my situation here related to the comments.

For example, you have a variable v1, if you write a formula and then followed by a comment out formula like this:

(some formula)

//(some formula)

When you use the variable alone in the expressions, it will work.

But if you use the variable with other variables like ($(1))/($(v2)), it will not work.

You need to change the order of the normal formula and comment out formula in order to make it work:

//(some formula)

(some formula)

Hope this would help

PC

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

That's interesting. It kind of makes sense, and kind of not. If

v1 = 4 // this is a comment

v2 = 3

$(v1) / $(v2) = 4 because the comment is included.

However.

$(v1) = 4.  The comment does not appear in final result.

-Rob