Export dimensional hierarchy to relational source

Post Reply
HurricaneDitka
Posts: 2
Joined: Thu Oct 22, 2009 5:54 pm
OLAP Product: TM1
Version: 9.4
Excel Version: 2007

Export dimensional hierarchy to relational source

Post by HurricaneDitka »

Hi,

Is there anyway to export a dimension with hierarchy in tact to a database table? I have a scenario where we load a flat chart of accounts into TM1 and set up our hierarchy structure within the dimension (i.e. specify that the Advertising Account rolls into Marketing Expenses > Total Expenses > Income Before Taxes). I need to reference that hierarchy from a relational source.

I'm aware of the ability to export a dimension to a cma and have worked with the ODBCOutput function as well... but these do not produce desired results as parents are all in one column. I'm looking for a solution that produces columns representing each level in the hierarchy. For example

Column: Acct_Level1 / Acct_Level2 / Acct_Level3 / Acct_Detail
Data: Income Before Taxes / Total Expenses / Marketing Expenses / Advertising

Thanks in advance for any advice!
David Usherwood
Site Admin
Posts: 1458
Joined: Wed May 28, 2008 9:09 am

Re: Export dimensional hierarchy to relational source

Post by David Usherwood »

You will probably need to do some work with TI to get the structures flowing the way you want eg (in pseudocode)
Read all items
if level0 then
output elem, par, gp, ggp, gggp
else skip

But this does depend on you having a nice simple level based structure. It's pretty common for a TM1 hierarchy not to be like that.

We have built a routine which transfers dimensions between servers (and between TM1 versions!) using a relational store. You only need a couple of tables to move all dimensions in a server. But you'd have to work on it to get it usable in a dimensionally modelled relational world.
HurricaneDitka
Posts: 2
Joined: Thu Oct 22, 2009 5:54 pm
OLAP Product: TM1
Version: 9.4
Excel Version: 2007

Re: Export dimensional hierarchy to relational source

Post by HurricaneDitka »

I'm not sure how to identify the parent of an element. Would I have to set up the dimension with attributes describing the parents? (Not desirable as this is an added layer of maintenance as account hierarchy changes). Or is there functionality available to get the parent?

As for our hierarchy, it's ragged... but is level based.

Thanks again!
User avatar
Michel Zijlema
Site Admin
Posts: 713
Joined: Wed May 14, 2008 5:22 am
OLAP Product: TM1, PALO
Version: both 2.5 and higher
Excel Version: 2003-2007-2010
Location: Netherlands
Contact:

Re: Export dimensional hierarchy to relational source

Post by Michel Zijlema »

Hi,

You can determine the parent of an element using the function ElPar(dimname, element, index).
The tricky thing is the index parameter. If you have multiple alternative hierarchies in the dimension an element can have multiple parents.
If each element can only have one parent setting the index parameter to 1 will do. Otherwise you need to loop (using While) through all parents the elements has. The function ElParN(dimname, element) will return the number of parents for the element.

Michel
dnicol
Posts: 2
Joined: Mon Jan 31, 2011 11:30 pm
OLAP Product: TM1, SSAS
Version: 9.5.1
Excel Version: 2007

Re: Export dimensional hierarchy to relational source

Post by dnicol »

Hello,
For anybody else who finds this thread and wants some example syntax - I have a similar requirement that I just coded up in a TI to export a dimension hierarchy to SQL Server. I'm pretty new to TM1 so sometimes even simple things like this can take a while (no thanks to TM1's ancient IDE and debugging features grrr).

Anyway, below shows the data tab logic/while loop required to accommodate the circumstance where a child may have multiple parent elements (as discussed earlier in the thread). Once I get the data in SQL Server I can easily recreate the parent child relationship using SQL.

Code: Select all

sSQL = '';

CountofParent = ElParN('Account', Account);
ElementLevel = ElLev('Account', Account);
ParentCounter = 0;

WHILE (ParentCounter <= CountofParent);

ParentElement = ElPar('Account', Account ,ParentCounter);

sSQL = Expand('INSERT INTO dbo.AccountTable (Account, parentelement, countofparent, elementlevel) VALUES (''%Account%'',''%ParentEl
ement%'',''%CountofParent%'', ''%ElementLevel%'')');

ODBCOutPut('SQLDEV', sSQL );

ParentCounter = ParentCounter+1;
END;
Post Reply