dynamic variable name in TI formula?

Post Reply
Schatrandsch
Posts: 3
Joined: Tue Jun 12, 2012 8:29 pm
OLAP Product: Planning Analytics/TM1
Version: 2.0.6
Excel Version: 2016

dynamic variable name in TI formula?

Post by Schatrandsch »

Hello,

I can use variables in formulas, of course.
But can I define which variable to use itself within a formula?
So far I can create the variable name by code, but that produces only a string with the name of the variable.

I simplified my code to zoom on my problem.
I want to get rid of the lines with the IF-clauses and replace them by 2 lines with "a=***" and "b=***".

So if I replace for instance
************************************************
IF ( index = 1);
a = level_1;
b = level_2;
ENDIF;
************************************************
with a code like this
************************************************
a = 'level_' | NUMBERTOSTRING(NUMBR(SUBST(a,7,1))-1);
************************************************
then I would get a string and not a variable.
So I cannot get rid of the lines for all the IF-clauses.

Is there a way to say "use the string as variable name"?
Or any other way?
This would help me in general to make code more usable and to use it untouched in different situations.

My code (simplified):
************************************************
###maximum of 10 levels
number_of_levels=6;

### Loop
index=number_of_levels-1;
WHILE( index >0 );
IF (a@<>b);
DIMENSIONELEMENTINSERT(vDim,'',a,'c');
DIMENSIONELEMENTCOMPONENTADD(vDim,a,b,1.000000);
ENDIF;
index = index-1;
IF ( index = 1);
a = level_1;
b = level_2;
ENDIF;
IF ( index = 2);
a = level_2;
b = level_3;
ENDIF;
IF ( index = 3);
a = level_3;
b = level_4;
ENDIF;
IF ( index = 4);
a = level_4;
b = level_5;
### further conditions for index values if more Levels exist
ENDIF;
END;
************************************************

Thanks in advance
lotsaram
MVP
Posts: 3703
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: dynamic variable name in TI formula?

Post by lotsaram »

Schatrandsch
Posts: 3
Joined: Tue Jun 12, 2012 8:29 pm
OLAP Product: Planning Analytics/TM1
Version: 2.0.6
Excel Version: 2016

Re: dynamic variable name in TI formula?

Post by Schatrandsch »

Thank you lotsaram!

Now I remember, that I have read about this a while ago.

It wirks now this way:

LevelAntecessor = EXPAND ( '%' | 'level' | NUMBERTOSTRING(index) | '%' );
LevelSuccessor = EXPAND ( '%' | 'level' | NUMBERTOSTRING(index+1 ) | '%' );
Post Reply