Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

frinfo
New Contributor

nested variables

Hi everybody,

it's my first post on this community.

I have defined 2 variables (var1,var2). The first variable is an expression of fields extracts from my LOAD and it works well. var1 = Sum([Field1])+Sum(Field2])

The second var is an expression of my first var (var1) and some fields extracts from my LOAD. In this case my expression returns null, because it looks like it not evaluate my first var. var2 = $(var1) + sum([Field3])

How can i use a var in the expression of another var?

Best regards

1 Solution

Accepted Solutions
MVP
MVP

Re: nested variables

Try to remove this equal sign here

Capture.PNG

or if you want to use the equal sign, try to use your variable without a dollar sign expansion and see if that helps you resolve your issue.

6 Replies
vishsaggi
Esteemed Contributor III

Re: nested variables

Try this may be:

SET vFlag  =  = Sum(Field1) + Sum(Field2);

SET vFinal =  = $(vFlag) + Sum(Field3);

frinfo
New Contributor

Re: nested variables

I attach the image of my problem:

view.png

The column [expression] is made by this expression:

=($(Qtà 1 Lvl DiBa)*[Qtà 2° Livello])+($(Qtà 1 Lvl DiBa)*(if(isnull([Sfrido % Medio]),0,[Sfrido % Medio]))/100)


The column [variables] is made by this expression:

=$(Qtà 2 Lvl DiBa)

In my sheet i have defined in "view variables..."

variable1.png

variable2.png

The expression of the column [expression] (marked green) is the same expression defined in the variable [Qtà 2 Lvl DiBa] set in the column [variables]

My question is: why the result of column [variables] is "-" (null) and in the result of column [expression] is correct?

I hope i have explained the situation.

Thank you in advance

MVP
MVP

Re: nested variables

Try to remove this equal sign here

Capture.PNG

or if you want to use the equal sign, try to use your variable without a dollar sign expansion and see if that helps you resolve your issue.

vishsaggi
Esteemed Contributor III

Re: nested variables

Can you try using quotes around your variables and try? If not could you please upload this sample to work on it quickly?

Like: Can you try this

= ('$(Qtà 1 Lvl DiBa)' * [Qtà 2° Livello])+ ( '$(Qtà 1 Lvl DiBa)'  *  (if(isnull([Sfrido % Medio]),0,[Sfrido % Medio]))/100)

effinty2112
Honored Contributor

Re: nested variables

Hi Francesco,

You could try RangeSum( $(var1) , sum([Field3])) instead of ' + '. Rangesum treats a non numeric or a null argument as a zero rather than throwing an error like '+'. Maybe that will solve the problem.

Cheers

Andrew

frinfo
New Contributor

Re: nested variables

Thank to everyone for trying to help me.

The answer of Sunny solve my problem.

Best regards

Community Browser