Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
jcampbell
Contributor

Set Year Variable in Load Script

I have a QVW wherein several objects use one of three variables either when displaying information or when calculating expressions:

1. vYear_Current

2. vYear_Previous

3. vYear_PreviousX2

I want to have these variables set to the appropriate values when data is loaded into the file. For example, if I loaded data today I would want:

vYear_Current = "2012"

vYear_Previous = "2011"

vYear_PreviousX2 = "2010"

I tried using the following in my load script but it did not work:

SET vYear_Current = YEAR(now());

SET vYear_Current = YEAR(now(-1));

SET vYear_Current = YEAR(now(-2));

Any ideas?

Thanks,

Josh

1 Solution

Accepted Solutions

Re: Set Year Variable in Load Script

Hi Josh,

Use the following instead. LET evaluates the function, then stores into the variable. SET only stores.

LET vYear_Current = Year(Today());

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

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

Hope that helps.

Miguel

3 Replies

Re: Set Year Variable in Load Script

Hi Josh,

Use the following instead. LET evaluates the function, then stores into the variable. SET only stores.

LET vYear_Current = Year(Today());

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

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

Hope that helps.

Miguel

pgalvezt
Valued Contributor

Re: Set Year Variable in Load Script

Hello, If I Want the months of this year it would be?

LET vYear_Current = Year(Month((Today())); Jun
LET vYear_Current = Year(Month(Today())) -1; May
LET vYear_Current = Year(Month(Today())) -2; Apr

Thanks,

Re: Set Year Variable in Load Script

Hi,

I'd rather use complete dates or at least, month date combination, as long as you already have a field with the same format in your calendar:

LET vCurrentMonth = MonthName(Today());

LET vPreviousMonth = MonthName(AddMonths(Today(), -1));

LET vPrePreviousMonth = MonthName(AddMonths(Today(), -2));

As mentioned, you need a field in your calendar built with MonthName.

Hope that helps.

Miguel

P.S.: Please next time open a new thread, this one was closed six months ago.

Community Browser