Qlik Community

Ask a Question

New to QlikView

If you’re new to QlikView, start with this Discussion Board and get up-to-speed quickly.

Qlik Highlights 2020 Giveaway! Watch, reply and have a chance to win a $200 Amazon Gift Card! Watch Video
Showing results for 
Search instead for 
Did you mean: 

Set analysis expression into variable, issue with date


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 :


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

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.