Page 1 of 1

Question about While Loop

Posted: Wed Dec 09, 2020 4:38 pm
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

Re: Question about While Loop

Posted: Wed Dec 09, 2020 5:21 pm
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;

Re: Question about While Loop

Posted: Thu Dec 10, 2020 3:29 am
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.

Re: Question about While Loop

Posted: Thu Dec 10, 2020 9:13 am
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;