Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
Announcing the newest addition to the Qlik Community, Qlik Gallery! Learn More
Highlighted
Partner
Partner

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

Re: Qlik Sense: Load Year & Month Variables

Hi,

Try something like

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

Hope it helps!!

Partner
Partner

Re: Qlik Sense: Load Year & Month Variables

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

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

Partner
Partner

Re: Qlik Sense: Load Year & Month Variables

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);

klewandowski
New Contributor III

Re: Qlik Sense: Load Year & Month Variables

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

Partner
Partner

Re: Qlik Sense: Load Year & Month Variables

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