Page 1 of 1

Rolling 12 Months with Description

Posted: Wed Nov 26, 2014 8:42 pm
by manu0521
Hi All,

I am new to TM1 and I am using TI process to create dimensions.

I am creating a time dimension with rolling 12 months. I am using the below logic to create it.

#************* ROLLING 12 FULL MONTHS **********************************************************************************************

sElement = 'Rolling 12 Full Months';

IF ( DIMIX ( sDateDim , sElement ) = 0 );

# create elements
DimensionElementInsert ( sDateDim , '' , sElement , 'N' );
DimensionElementComponentAdd ( sDateDim , sParent , sElement , 1 );
ENDIF;

# get last month - can get this from the "Last Month" element above

#get first month
IF ( nMonthLast = 12 );
nMonthFirst = 1;
nYearFirst = nYearLast;
ELSE;
nMonthFirst = nMonthLast + 1;
nYearFirst = nYearLast -1;
ENDIF;

nPeriodFirst = nYearFirst * 100 + nMonthFirst;
nPeriodLast = nYearLast * 100 + nMonthLast;

nPeriod = nPeriodFirst;
nMonth = nMonthFirst;
n = 1;

While ( n <= 12 );
#get month and add to element

sDate = STR( nPeriod , 6 , 0 );

IF (DIMIX( sDateDim , sDate) <> 0 );

sDate = DIMNM ( sDateDim , DIMIX ( sDateDim , sDate ) );
DimensionElementComponentAdd ( sDateDim , sElement , sDate , 1 );
else;
# exception!

ENDIF;

IF (nMonth = 12 );
# increment years as well
nPeriod = nPeriod + 89;
nMonth = 1;

ELSE;
nPeriod = nPeriod + 1;
nMonth = nMonth + 1;
ENDIF;

n = n + 1;
END;


Here my values are added like 201401 , 201402,201403 etcc....

Instead I want my values to be Jan 2014 , feb 2014..

How can I convert the string 201402 to feb 2014. Is the above approach right for creating this element,


Thanks,
Manu

Re: Rolling 12 Months with Description

Posted: Wed Nov 26, 2014 11:05 pm
by declanr
If you want to get the month in MMM format you can use the TimSt function and then concatenate the result for your year. You need to pass a serial date into the TimSt function but you can get that from DayNo (and pass a date into that - you can use any static day and year as it's only the month you are interested in.)

Re: Rolling 12 Months with Description

Posted: Wed Dec 03, 2014 12:52 am
by RJ!
Why not something like this?

Code: Select all

# Monthly Subsets

MyDimMth = 'Period' ;

# 1st Instance Variables
MySub2 = 'Sys_Last 12 Mths' ;
MyVar = 12 ;

# Check if Subset Exists, delete elements if true
If ( SubsetExists(MyDimMth, MySub2) = 1 ) ;
# Delete Existing Elements in Subset
   SubsetDeleteAllElements(MyDimMth, MySub2);
Endif;

# Build MDX String with CurrDate Variable
MyMDX = 'LastPeriods(' | NumbertoString(MyVar) | ', [' | MyDimMth | '].[' | CurrMth | '])' ;

# Execute Bedrock process to re-insert Elements
Executeprocess( 'Redbock.Dim.Sub.Create.ByMDX', 'pDimension', MyDimMth, 'pSubset' , MySub2 , 'pMDXExpr' ,  MyMDX ) ;