Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
emmanueld
Partner - Creator
Partner - Creator

Set analysis expression into variable, issue with date

Hello,

I'm having an issue when trying to put an expression into a variable.

I have a text object with the following expression, giving the right number (production of last year before the current month) :

=Num(Sum({1<Year = {$(=v_YearReference-1)}, Month = {"<=$(v_MonthReference)"}, [_REF_DESC] = {"Actual"}, FACT_TYPE_ID={"PKG02"} >} [FACT_VALUE]), '# ##0')

I want to put this expression into a variable in order to have all expressions visible in the script and make maintenance easier. So I did the following in the script :

SET v_ProducedYTDPreviousYear = Num(Sum({1<Year = {$(=v_YearReference-1)}, Month = {"<=$(v_MonthReference)"}, [_REF_DESC] = {"Actual"}, FACT_TYPE_ID={"PKG02"} >} [FACT_VALUE]), '# ##0');

...and I put this in the text object :

=$(v_ProducedYTDPreviousYear)

My issue is that I now have 0 displayed in the text object, and I don't know why. Maybe it has something to do with SET/LET or the way I calculate the year and month, but I'm quite new to Qlikview and don't understand everything.

Note : There if I put =v_ProducedYTDPreviousYear, it shows the expression with Year={}.

Note2: The same expression works if I use $(v_YearReference) instead of $(=v_YearReference-1). What is the difference?

Thank you for your help

1 Reply
emmanueld
Partner - Creator
Partner - Creator
Author

I found out what my issue was. I shouldn't have put my expressions in the script, but directly in the variable overview.
The difference :

- with the expressions in the script, the {$(=xxx)} inside the expression are calculated when executing the script.

- with the expressions in the variable overview, the whole expression is calculated at runtime, so {$(=xxx)} is too.