Counter in while loop
-
- Posts: 20
- Joined: Fri May 11, 2012 9:57 am
- OLAP Product: TM1
- Version: 10.1.1
- Excel Version: 2010
Counter in while loop
Hi all,
I have a large number of elements I want to add to a dimension in TI,
i.e.
DimensionElementInsert('Department','',Department_1,'S');
DimensionElementInsert('Department','',Department_2,'S');
DimensionElementInsert('Department','',Department_3,'S');
DimensionElementInsert('Department','',Department_4,'S');
DimensionElementInsert('Department','',Department_5,'S');
(etc.)
Is it possible to create a counter (i) that I can substitute into the department variables (e.g. Department_i) with a WHILE loop?
Thanks in advance.
I have a large number of elements I want to add to a dimension in TI,
i.e.
DimensionElementInsert('Department','',Department_1,'S');
DimensionElementInsert('Department','',Department_2,'S');
DimensionElementInsert('Department','',Department_3,'S');
DimensionElementInsert('Department','',Department_4,'S');
DimensionElementInsert('Department','',Department_5,'S');
(etc.)
Is it possible to create a counter (i) that I can substitute into the department variables (e.g. Department_i) with a WHILE loop?
Thanks in advance.
-
- Posts: 110
- Joined: Wed May 20, 2009 7:30 am
- OLAP Product: TM1
- Version: 10.2.2 - PA
- Excel Version: 2010
- Location: Rennes, France
Re: Counter in while loop
Hi,
Yes, it is. That would be something like that (not tested...):
i=1;
While (i<=200);
DimensionElementInsert('Department','','Department_'|i,'S');
i=i+1;
end;
Your element names would then be:
Department_1
Department_2
...
Department_200
Is that what you're looking for?
HTH
Yes, it is. That would be something like that (not tested...):
i=1;
While (i<=200);
DimensionElementInsert('Department','','Department_'|i,'S');
i=i+1;
end;
Your element names would then be:
Department_1
Department_2
...
Department_200
Is that what you're looking for?
HTH
-
- Posts: 20
- Joined: Fri May 11, 2012 9:57 am
- OLAP Product: TM1
- Version: 10.1.1
- Excel Version: 2010
Re: Counter in while loop
Hi Catherine,
I'm referencing Department_1, Department_2, etc. directly as variables.
Enclosing them in inverted commas populates the dimension with the text within. I'm after the variables values. So I cannot use the inverted commas.
Thanks.
I'm referencing Department_1, Department_2, etc. directly as variables.
Enclosing them in inverted commas populates the dimension with the text within. I'm after the variables values. So I cannot use the inverted commas.
Thanks.
-
- MVP
- Posts: 1827
- 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: Counter in while loop
Catherine has answered the question but I think the code needs just 1 small tweak, in the case above i is a numeric term so when stating 'Department_' | i the code may not work due to i not being string as such it could simply be replaced with 'Department_' | NumberToString ( i )Catherine wrote:Hi,
Yes, it is. That would be something like that (not tested...):
i=1;
While (i<=200);
DimensionElementInsert('Department','','Department_'|i,'S');
i=i+1;
end;
Your element names would then be:
Department_1
Department_2
...
Department_200
Is that what you're looking for?
HTH
e.g.
i=1;
While (i<=200);
DimensionElementInsert('Department','','Department_'|NumberToString ( i ) ,'S');
i=i+1;
end;
Declan Rodger
-
- MVP
- Posts: 1827
- 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: Counter in while loop
Michael Barker wrote:Hi Catherine,
I'm referencing Department_1, Department_2, etc. directly as variables.
Enclosing them in inverted commas populates the dimension with the text within. I'm after the variables values. So I cannot use the inverted commas.
Thanks.
If Department_1 and Department_2 are variables then why don't you just populate in the metadata tab with a simple
DimensionElementInsert( 'Dim', '', v1, 'S');
Or do you mean that they are the names of the variables as opposed to the variable values?
Declan Rodger
-
- Posts: 20
- Joined: Fri May 11, 2012 9:57 am
- OLAP Product: TM1
- Version: 10.1.1
- Excel Version: 2010
Re: Counter in while loop
They are variable names. There's s lot of them. I can copy/paste the code for all of them in the metadata tab, but that just seems unnecessary.
-
- MVP
- Posts: 1827
- 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: Counter in while loop
I'm not sure I entirely understand the problem.
Could you provide an example csv of the datasource and explain what you want to be created?
Could you provide an example csv of the datasource and explain what you want to be created?
Declan Rodger
-
- Posts: 3
- Joined: Thu Jul 19, 2012 12:32 pm
- OLAP Product: TM1
- Version: 9.4.1
- Excel Version: 2003
Re: Counter in while loop
I think that you want to retrieve the variable name from the concatenation of 'Departement_' and a number i in your while.
I think that you should try the "Expand" function.
Something like that "expand('%Departement_'|numbertostring(i)|'%')" should give you the variable value.
Is that correct?
I think that you should try the "Expand" function.
Something like that "expand('%Departement_'|numbertostring(i)|'%')" should give you the variable value.
Is that correct?
-
- Posts: 20
- Joined: Fri May 11, 2012 9:57 am
- OLAP Product: TM1
- Version: 10.1.1
- Excel Version: 2010
Re: Counter in while loop
Expand() is what I was looking for. Let me try it out.
Thanks!
Thanks!
-
- Posts: 3
- Joined: Thu Jul 19, 2012 12:32 pm
- OLAP Product: TM1
- Version: 9.4.1
- Excel Version: 2003
Re: Counter in while loop

Tell me if it worked

-
- Posts: 11
- Joined: Thu Jun 26, 2008 12:07 pm
- OLAP Product: IBM Cognos TM1
- Version: 10.2
- Excel Version: 2010
- Location: Germany
Re: Counter in while loop
It should be a double Expand. The inner one to get the name and the outer one to get the value.
- Steve Rowe
- Site Admin
- Posts: 2455
- Joined: Wed May 14, 2008 4:25 pm
- OLAP Product: TM1
- Version: TM1 v6,v7,v8,v9,v10,v11+PAW
- Excel Version: Nearly all of them
Re: Counter in while loop
http://www.tm1forum.com/viewtopic.php?f=21&t=4921
A few examples here on the use of expand to manipulate variable names.
I think you only need a single expand.
Double expand is when the value you need is held in a variable that is itself the value of antother variable....
A few examples here on the use of expand to manipulate variable names.
I think you only need a single expand.
Double expand is when the value you need is held in a variable that is itself the value of antother variable....
Technical Director
www.infocat.co.uk
www.infocat.co.uk
-
- Posts: 20
- Joined: Fri May 11, 2012 9:57 am
- OLAP Product: TM1
- Version: 10.1.1
- Excel Version: 2010
Re: Counter in while loop
Thanks all, works fantastically.
Code: Select all
WHILE()
j = NUMBERTOSTRING(i);
DIMENSIONELEMENTINSERT('Department','',EXPAND('%Department_'|EXPAND('%j%')|'%'),'S');
i = i +1
END
- Steve Rowe
- Site Admin
- Posts: 2455
- Joined: Wed May 14, 2008 4:25 pm
- OLAP Product: TM1
- Version: TM1 v6,v7,v8,v9,v10,v11+PAW
- Excel Version: Nearly all of them
Re: Counter in while loop
Except you only need on expand
DIMENSIONELEMENTINSERT('Department','',EXPAND('%Department_'| j|'%'),'S');
will work too
DIMENSIONELEMENTINSERT('Department','',EXPAND('%Department_'| j|'%'),'S');
will work too
Technical Director
www.infocat.co.uk
www.infocat.co.uk