Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
jcampbell
Partner - Creator
Partner - Creator

Qlik Sense: Load Year & Month Variables

I'm trying to use a script (which I've successfully implemented with QlikView) in Qlik Sense. Basically I need to store a few variables for Year and Month (current, previous, etc). Here's the script I'm using:

LET vYearCurrent = Year(Today());

LET vYearPrevious = Year(Today())-1;

LET vYearPreviousX2 = Year(Today())-2;

LET vMonthCurrent = Month(Today());

LET vMonthPrevious = Month(Today())-1;

LET vMonthPreviousX2 = Month(Today())-2;

For some reason Sense stores "Sep" for the value of vMonthCurrent but "8" for the value of vMonthPrevious. As a result I'm only able to use the vMonthCurrent variable in my visualization and not the vMonthPrevious variable.

Any ideas how to get Sense to not store the vMonthPrevious variable value as numeric?

5 Replies
Not applicable

Hi,

Try something like

vMonthPrevious =month(monthstart(today())-1)

Hope it helps!!

phaneendra_kunc
Partner - Specialist III
Partner - Specialist III

Once you subtract number it will convert the strings into numbers. for Previousmonth use below..

Month(AddMonths(Today(),-1))

jcampbell
Partner - Creator
Partner - Creator
Author

That did it. Thanks! Here's the final script:

LET vYearCurrent = Year(Today());

LET vYearPrevious = Year(YearStart(Today())-1);

LET vYearPreviousX2 = Year(YearStart(Today())-2);

LET vMonthCurrent = Month(Today());

LET vMonthPrevious = Month(MonthStart(Today())-1);

LET vMonthPreviousX2 =  Month(MonthStart(Today())-2);

Anonymous
Not applicable

Hi. Im quite newbie in QlikSense after working in QlikView. I try to use variables but somehow it doesnt work the way i was working in QlikView.

I want to write expression showing sum of sales for previous year  but expresion like

Sum(if(YEAR=vYearPrevious,Sales)) doesnt work.

How am I supposed to use it? I pasted variables from this discussion to Script and reloaded app.

Thanks in advance for help

jcampbell
Partner - Creator
Partner - Creator
Author

Your expression should be Sum({<[Year]={'$(vYearPrevious)'}>}[Sales]).