
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Try something like
vMonthPrevious =month(monthstart(today())-1)
Hope it helps!!


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Once you subtract number it will convert the strings into numbers. for Previousmonth use below..
Month(AddMonths(Today(),-1))

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your expression should be Sum({<[Year]={'$(vYearPrevious)'}>}[Sales]).
