8 Replies Latest reply: Jun 5, 2013 4:43 PM by Stefan Wühl

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

• ###### Re: Using variables in expression functions

Prueba

=sum(\$(vSales))

• ###### Re: Using variables in expression functions

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

• ###### Re: Using variables in expression functions

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

• ###### Re: Using variables in expression functions

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

• ###### Re: Using variables in expression functions

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

• ###### Re: Using variables in expression functions

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

• ###### Re: Using variables in expression functions

use

=\$(vSales)

sin utilizar el Sum(vSales)

• ###### Re: Using variables in expression functions

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)