Question about While Loop

Post Reply
NewtoTM1P
Posts: 5
Joined: Wed Dec 09, 2020 3:42 pm
OLAP Product: TM1
Version: lastest
Excel Version: lastest

Question about While Loop

Post by NewtoTM1P »

Hi, I started using TM1 a few weeks ago, and I have encountered a problem related to looping.
As I would like to use the looping for the CellincrementN, but I am not sure how to apply that.

The situation is about I am selling 5 different fruits in 5 different stores, and each of the fruits is selling a different price in different stores. Therefore, it would have 25 combinations/price. And, all the information above in is excel which is the data source.

Also, I am going to sell those fruits in different regions as well, so I created a cube with the 3 dimensions (Fruits, Stores, Regions). However, the data sources do not contain information about the region, even I make up some n-level element in the region dimension. So, I am thinking about how to load that 25 combinations into a different region by using CellincrementN and the Loop. I also assumed that the price would be the same in different regions. Sorry for the bad English, and appreciate any help. :D
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Question about While Loop

Post by tomok »

You can use the DIMSIZ function to get the number of elements in your Region dimension, assign that number to a variable and then do a loop:

Code: Select all

nSize = DIMSIZ('Server:Region');
i = 0;
WHILE (i <= nSize);
  Do something;
  i = i + 1;
END;
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
NewtoTM1P
Posts: 5
Joined: Wed Dec 09, 2020 3:42 pm
OLAP Product: TM1
Version: lastest
Excel Version: lastest

Re: Question about While Loop

Post by NewtoTM1P »

tomok wrote: Wed Dec 09, 2020 5:21 pm You can use the DIMSIZ function to get the number of elements in your Region dimension, assign that number to a variable and then do a loop:

Code: Select all

nSize = DIMSIZ('Server:Region');
i = 0;
WHILE (i <= nSize);
  Do something;
  i = i + 1;
END;
There is also a C-level called 'All region', do I need extra function to skip that as well? ;) Thank you.
Wim Gielis
MVP
Posts: 3233
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: Question about While Loop

Post by Wim Gielis »

Code: Select all

i = 1;
WHILE( i <= DIMSIZ( 'Region' ));
  vRegion = DIMNM( 'Region', i );
  IF( DTYPE( 'Region', vRegion ) @= 'N' );
     # ...
  ENDIF;
  i = i + 1;
END;
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
Post Reply