Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Current Year and Last Year Flags

I am trying to put a CY and LY flag into my script but everything I try gives me errors.

I am loading essentially one giant ascii with all my records. [INVC DATE] is only one of these fields. When i try this...

[INVC DATE],



date(monthstart([INVC DATE]), 'MMM-YYYY') as RollingMonth,

date

(yearstart([INVC DATE]), 'YYYY') as RollingYear,

Month

(Date([INVC DATE])) as Month,

Weekday

([INVC DATE]) as WeekDay,

Day

([INVC DATE]) as Day,

Week

([INVC DATE]) as Week,



Week

([INVC DATE])&'-'&Year([INVC DATE]) as RollingWeek,



IF

(year([INVC DATE])=$(vCurrentYear),1,0) AS CY_flag,



IF

(year([INVC DATE])=($(vCurrentYear)-1),1,0) AS LY_flag,

I get Error in expression:')' expected

Much appreciate some guidance here,



1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

It should be:

if(year([INVC_DATE])=year(today()), 1, 0) as CY_flag
if(year([INVC_DATE])=(year(today())-1), 1, 0) as LY_flag

View solution in original post

4 Replies
Not applicable
Author

I have made a temporary fix by changing $VcurrentYear to '2010' but would really like to get this right for future years

Anonymous
Not applicable
Author

It should be:

if(year([INVC_DATE])=year(today()), 1, 0) as CY_flag
if(year([INVC_DATE])=(year(today())-1), 1, 0) as LY_flag

Not applicable
Author

Les -

There's also the InYear() function:


LET varToday = NUM(TODAY());
MasterCalendar:
TempDate AS OrderDate,
INYEAR(TempDate, $(varToday), 0) * -1 AS CurYearFlag,
INYEAR(TempDate, $v(varToday), -1) * -1 AS LastYearFlag
RESIDENT TempCalendar;


Not applicable
Author

Thanks!