Building a Rolling 13Week Period Dimension
Posted: Fri Dec 05, 2008 5:14 am
I am trying to build a rolling 13week Period dimension using TI. I have got the dimension populating with the 91 days (Today to 13weeks in the future).
METADATA
nCurrDate = DAYNO(TODAY);
nCurrWeek = WEEKNUM(TODAY);
WHILE(nCounter<nStop);
sysDate = DATE(nCurrDate);
currMonth = SUBST(sysDate, 4, 2);
#CHANGE THE MONTH TO A MMM FORMAT
mmmMonth = IF(currMonth@= '01', 'Jan',
IF(currMonth@= '02', 'Feb',
IF(currMonth@= '03', 'Mar',
IF(currMonth@= '04', 'Apr',
IF(currMonth@= '05', 'May',
IF(currMonth@= '06', 'Jun',
IF(currMonth@= '07', 'Jul',
IF(currMonth@= '08', 'Aug',
IF(currMonth@= '09', 'Sep',
IF(currMonth@= '10', 'Oct',
IF(currMonth@= '11', 'Nov', 'Dec')))))))))));
sCurrDate = SUBST(sysDate, 7, 2) | '-' | mmmMonth | '-' | SUBST(sysDate, 1, 2);
DimensionElementInsert(dPeriod, '', sCurrDate, 'N');
nCounter = nCounter+1;
nCurrDate = nCurrDate + 1;
END;
Now I need to consolidate the elements into weekly groups (Week1 to Week13) ie Week 1 Wed - Sun and Week 13 Mon - Tue. Without a WeekNum function I can't see any way to derive the week in which day falls. If anyone has come across this problem before or has an ideas that would be great.
Cheers,
Robert
METADATA
nCurrDate = DAYNO(TODAY);
nCurrWeek = WEEKNUM(TODAY);
WHILE(nCounter<nStop);
sysDate = DATE(nCurrDate);
currMonth = SUBST(sysDate, 4, 2);
#CHANGE THE MONTH TO A MMM FORMAT
mmmMonth = IF(currMonth@= '01', 'Jan',
IF(currMonth@= '02', 'Feb',
IF(currMonth@= '03', 'Mar',
IF(currMonth@= '04', 'Apr',
IF(currMonth@= '05', 'May',
IF(currMonth@= '06', 'Jun',
IF(currMonth@= '07', 'Jul',
IF(currMonth@= '08', 'Aug',
IF(currMonth@= '09', 'Sep',
IF(currMonth@= '10', 'Oct',
IF(currMonth@= '11', 'Nov', 'Dec')))))))))));
sCurrDate = SUBST(sysDate, 7, 2) | '-' | mmmMonth | '-' | SUBST(sysDate, 1, 2);
DimensionElementInsert(dPeriod, '', sCurrDate, 'N');
nCounter = nCounter+1;
nCurrDate = nCurrDate + 1;
END;
Now I need to consolidate the elements into weekly groups (Week1 to Week13) ie Week 1 Wed - Sun and Week 13 Mon - Tue. Without a WeekNum function I can't see any way to derive the week in which day falls. If anyone has come across this problem before or has an ideas that would be great.
Cheers,
Robert