Export TM1 Dimension to file
-
- Posts: 11
- Joined: Wed Oct 19, 2011 5:11 pm
- OLAP Product: Cognos TM1
- Version: Planning Analytics 2.0.6 IF4
- Excel Version: 365 ProPlus v2016
Export TM1 Dimension to file
Does anyone know how to write the TM1 TI Process that will export a dimension to a text file in the same exact format as when you right-click on the dimension and choose "Export Dimension..."? There will be dimensions that have multiple hierarchies mind you. I have been able to export them using a TI Process to a flat file (Bedrock's dimension export scripting), but it is in a different format and then the person that needs the dimension export for a 3rd party BI system will have to redo all his existing scripting to bring it into that BI software. I'd like to avoid putting that burden on him. Thank you.
-
- MVP
- Posts: 1828
- Joined: Mon Dec 05, 2011 11:51 am
- OLAP Product: Cognos TM1
- Version: PA2.0 and most of the old ones
- Excel Version: All of em
- Location: Manchester, United Kingdom
- Contact:
Re: Export TM1 Dimension to file
I would question whether this is the best way to get the dimension data into an external tool but if it is what you wish to go with then the following should just about get you there (I have just written it now without testing so it may have typos etc but should explain the basic premise.)sdarpa wrote:Does anyone know how to write the TM1 TI Process that will export a dimension to a text file in the same exact format as when you right-click on the dimension and choose "Export Dimension..."? There will be dimensions that have multiple hierarchies mind you. I have been able to export them using a TI Process to a flat file (Bedrock's dimension export scripting), but it is in a different format and then the person that needs the dimension export for a 3rd party BI system will have to redo all his existing scripting to bring it into that BI software. I'd like to avoid putting that burden on him. Thank you.
Prolog:
Code: Select all
sDim = <dimension_name>;
sOutputFile = 'D:\' | sDim | '.csv';
Data:
Code: Select all
If ( DTYPE ( sDim, v1 ) @= 'C' );
AsciiOutput ( sOutputFile, 'C,' | v1 );
iCount = 1;
iMax = ElCompN ( sDim, v1 );
While ( iCount <= iMax );
sChild = ElComp ( sDim, v1, iCount );
sWeight = NumberToStringEx ( ElWeight ( sDim, v1, sChild ), '#.0,#########', '.',',' );
AsciiOutput ( sOutputFile, ',' | sChild | ',' | sWeight );
iCount = iCount + 1;
End;
ElseIf ( DTYPE ( sDim, v1 ) @='N' );
AsciiOutput ( sOutputFile, 'N,' | v1 );
ElseIf ( DTYPE ( sDim, v1 ) @='S' );
AsciiOutput ( sOutputFile, 'S,' | v1 );
EndIf;
You will need to have the dimension in your data source with the all subset, you could also set this in the prolog and just have a parameter to define the dimension so that 1 TI will work throughout your (and any) model.
HTH
Declan Rodger
-
- Posts: 11
- Joined: Wed Oct 19, 2011 5:11 pm
- OLAP Product: Cognos TM1
- Version: Planning Analytics 2.0.6 IF4
- Excel Version: 365 ProPlus v2016
Re: Export TM1 Dimension to file
Thanks a bunch!!!! It worked with just a few little tweaks.
-
- MVP
- Posts: 3234
- Joined: Mon Dec 29, 2008 6:26 pm
- OLAP Product: TM1, Jedox
- Version: PAL 2.1.5
- Excel Version: Microsoft 365
- Location: Brussels, Belgium
- Contact:
Re: Export TM1 Dimension to file
In the spirit of this forum, sharing knowledge and working solutions, please can you post up your final version of the code?sdarpa wrote:Thanks a bunch!!!! It worked with just a few little tweaks.
And/or the changes you did to Rodger's code. Thanks.
Best regards,
Wim Gielis
IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Wim Gielis
IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
-
- Posts: 11
- Joined: Wed Oct 19, 2011 5:11 pm
- OLAP Product: Cognos TM1
- Version: Planning Analytics 2.0.6 IF4
- Excel Version: 365 ProPlus v2016
Re: Export TM1 Dimension to file
Sure. I didn't need the file name in the output and the | signs in the Data tab were not helping. Prologue remained the same.
DATA tab:
DATA tab:
Code: Select all
If ( DTYPE ( sDim, v1 ) @= 'C' );
AsciiOutput ( sOutputFile, 'C', v1 );
iCount = 1;
iMax = ElCompN ( sDim, v1 );
While ( iCount <= iMax );
sChild = ElComp ( sDim, v1, iCount );
sWeight = NumberToString ( ElWeight ( sDim, v1, sChild ) );
AsciiOutput ( sOutputFile, '', sChild , sWeight );
iCount = iCount + 1;
End;
ElseIf ( DTYPE ( sDim, v1 ) @='N' );
AsciiOutput ( sOutputFile, 'N', v1 ); ElseIf ( DTYPE ( sDim, v1 ) @='S' );
AsciiOutput ( sOutputFile, 'S', v1 ); EndIf;
-
- MVP
- Posts: 3234
- Joined: Mon Dec 29, 2008 6:26 pm
- OLAP Product: TM1, Jedox
- Version: PAL 2.1.5
- Excel Version: Microsoft 365
- Location: Brussels, Belgium
- Contact:
Re: Export TM1 Dimension to file
The community thanks you 

Best regards,
Wim Gielis
IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Wim Gielis
IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
-
- MVP
- Posts: 733
- Joined: Wed May 14, 2008 11:06 pm
Re: Export TM1 Dimension to file
This could benefit only so slightly from reducing the amount of IF...ELSEIF logic:
Code: Select all
sElementType = DTYPE ( sDim, v1 );
# always output the element and its type
AsciiOutput ( sOutputFile, sElementType , v1 );
# cycle through children if it is a consolidated element
IF ( sElementType @= 'C' );
iCount = 1;
iMax = ElCompN ( sDim, v1 );
While ( iCount <= iMax );
sChild = ElComp ( sDim, v1, iCount );
sWeight = NumberToString ( ElWeight ( sDim, v1, sChild ) );
AsciiOutput ( sOutputFile, '', sChild , sWeight );
iCount = iCount + 1;
End;
EndIf;
Robin Mackenzie