Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using variables in expression functions

Let's say I have a variable vSales with a big nasty formula.

Why doesn't this work?  It seems like it is just calcing the variable and returning a value without regard to the new expression.

=Sum(vSales)

Does it have something to do with where the = sign is placed in the expression and/or the variable formula?

8 Replies
Anonymous
Not applicable
Author

Prueba

=sum($(vSales))

swuehl
MVP
MVP

It's probably due to the variable definition. Could you post the exact definition as shown in the variable overview?

Not applicable
Author

sorry, I didn't type out the whole thing...  it should be =sum($(vSales))

Not applicable
Author

I'm trying to simplify just to get the underlying reason for why this might happen, so let's just pretend it is something like this:

=sum({<Year={$(=year(today()))}>}Sales)

I found some things about how the variable behaves differently if the leading = sign is in the variable or not, and also something about putting an = sign next to the variable in the expression like this Sum($(=vSales)).  So I guess my question is are these things different?

sum({<Year={$(=year(today()))}>}Sales)   vs   =sum({<Year={$(=year(today()))}>}Sales)

sum($(=vSales))   vs   sum($(vSales))    vs   =sum($(vSales))   vs   =sum($(=vSales))

swuehl
MVP
MVP

Right, there are important differences, please see also

http://www.qlikfix.com/2011/06/08/not-all-variables-are-created-equal/

I haven't fully understood if

=sum({<Year={$(=year(today()))}>}Sales)

is your variable definition or

{<Year={$(=year(today()))}>}Sales

or...?

Not applicable
Author

=sum({<Year={$(=year(today()))}>}Sales) is the variable

Anonymous
Not applicable
Author

use

=$(vSales)

sin utilizar el Sum(vSales)

swuehl
MVP
MVP

christine.hill schrieb:

=sum({<Year={$(=year(today()))}>}Sales) is the variable

this will evaluate to a number, so whenever you are calling the variable, the result of the sum is returned.

Why are you trying to pass this value to another aggregation like sum() then?

(even if you remove the equal sign from the variable definition, you would try to evaluate a sum() inside a sum(), which is not working without the use of advanced aggregation aggr() function)