Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jcampbell
Partner - Creator
Partner - Creator

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
Miguel_Angel_Baeyens

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

View solution in original post

3 Replies
Miguel_Angel_Baeyens

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
Specialist
Specialist

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,

Miguel_Angel_Baeyens

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.