Page 1 of 1

Automatically update time dimension

Posted: Wed Feb 08, 2023 4:56 pm
by i.iescone
Hello everyone, I'm a starter in tm1 and I'd like to set up a chore that update the time dimension uploading all the months of the current year plus the first three months of the next one

So far this is my code..which doesn't work on a dummy dimension I used as data source. What do you suggest to go on with?


#Section Prologo

#****Begin: Generated Statements***

#****End: Generated Statements****

dimTempo='Time';

currentyear='2022';

nextyear='2023';



#Section Metadata

#****Begin: Generated Statements***

#****End: Generated Statements****



#Section Dati

#****Begin: Generated Statements***

#****End: Generated Statements****



i=1;

elemento= DIMNM( dimTempo, i );

while(DIMIX( dimTempo, elemento )=0);



if( DimensionElementExists( dimTempo, elemento )=1 );

DimensionElementDelete( dimTempo, elemento );

endif;



DimensionElementInsert( dimTempo, '', 'currentyear', 'C' );

DimensionElementComponentAdd( dimTempo, 'currentyear', '01|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '02|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '03|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '04|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '05|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '06|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '07|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '08|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '09|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '10|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '11|.|currentyear', 1 );

DimensionElementComponentAdd( dimTempo, 'currentyear', '12|.|currentyear', 1 );



DimensionElementInsert( dimTempo, '', 'nextyear', 'C' );

DimensionElementComponentAdd( dimTempo, 'nextyear', '01|.|nextyear', 1 );

DimensionElementComponentAdd( dimTempo, 'nextyear', '02|.|nextyear', 1 );

DimensionElementComponentAdd( dimTempo, 'nextyear', '03|.|nextyear', 1 );



i=i+1;

end;

Re: Automatically update time dimension

Posted: Wed Feb 08, 2023 6:47 pm
by gtonkin
A couple of things here but the main one is that your apostrophe should be after the month number and before the pipe, not after the year.

Edit: Also best to do meta data updates in meta data otherwise you may rather want to look at the Direct commands for your inserts.

Re: Automatically update time dimension

Posted: Thu Feb 09, 2023 1:23 am
by Wim Gielis
Hello, do you have access to a training course on TM1 ? Or qualified coworkers ?
This will be valuable I think to grasp the basics.