Deleting even elements from dimension with process

Post Reply
vasek1192
Posts: 47
Joined: Sun Jan 24, 2021 5:55 pm
OLAP Product: IBM Planning analytics
Version: 2.0.9.3
Excel Version: 2019

Deleting even elements from dimension with process

Post by vasek1192 »

Hi, This is my first post and first time working with TM1 Architect so sorry for elemental question.

Problem is as follows: I created Dimension with 100 elements 1-100, now I need to write separate process that will delete all even numbers from the dimension. I have some idea how to do this in the process creating the dimension but with separate process I dont even know where to start. So I would appreciate some pointers. Thanks.

Code: Select all

prefix = 'A_VNO_';
DimName = prefix | 'G_Rada';
LoopCounter = 1;

IF(DimensionExists(DimName)=0);
DimensionCreate(DimName);
ENDIF;

WHILE(LoopCounter <=100);

   ElName = NumberToString(LoopCounter);
   DimensionElementInsert(DimName, '', ElName, 'N');
   LoopCounter = LoopCounter + 1;

END;
lotsaram
MVP
Posts: 3651
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Deleting even elements from dimension with process

Post by lotsaram »

How would you do this in any other programming language?
Look up the MOD function.
... and don't forget that when deleting items it is much better to decrement through a list than increment!
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
vasek1192
Posts: 47
Joined: Sun Jan 24, 2021 5:55 pm
OLAP Product: IBM Planning analytics
Version: 2.0.9.3
Excel Version: 2019

Re: Deleting even elements from dimension with process

Post by vasek1192 »

Thanks, I solved it by this. Is there any more efficient way to do this? Thanks.

Code: Select all

DimName = 'A_VNO_G_Rada';
LoopCounter = 1;

WHILE(LoopCounter <=100);

IF(MOD(DIMIX(DimName, NumberToString(LoopCounter)),2)=0);

DimensionElementDelete(DimName, NumberToString(LoopCounter));

ENDIF;

LoopCounter = LoopCounter + 1;

END;
declanr
MVP
Posts: 1815
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: Deleting even elements from dimension with process

Post by declanr »

vasek1192 wrote: Thu Jan 28, 2021 12:57 pm Thanks, I solved it by this. Is there any more efficient way to do this? Thanks.
The way you have done it is pretty efficient and will work quickly.
However due to your specific requirement, you could have just started at 2 and worked in increments of 2.

Code: Select all

DimName = 'A_VNO_G_Rada';
LoopCounter = 2;

WHILE(LoopCounter <=100);
   DimensionElementDelete(DimName, NumberToString(LoopCounter));
   LoopCounter = LoopCounter + 2;
END;
Declan Rodger
vasek1192
Posts: 47
Joined: Sun Jan 24, 2021 5:55 pm
OLAP Product: IBM Planning analytics
Version: 2.0.9.3
Excel Version: 2019

Re: Deleting even elements from dimension with process

Post by vasek1192 »

Thank you, this is much simpler :)
User avatar
Steve Rowe
Site Admin
Posts: 2410
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: Deleting even elements from dimension with process

Post by Steve Rowe »

Just to be difficult we also need to make sure we understand the definition of "even". This won't always match off to the index or every other element. Both ways the code is written above make underlying assumptions about the structure of the dimension.
It might be right now but will it be right in the future?
Also think about what happens if your TI is run for a second time...

Code: Select all

DimName = 'A_VNO_G_Rada';
LoopCounter = 1;
Max=DimSiz(DimName);

WHILE(LoopCounter <=Max);
  sElName=Dimnm(DimName , LoopCOunter);
   IF(MOD(Numbr(sElName),2)=0);

    DimensionElementDelete(DimName, sElName);

  ENDIF;

 LoopCounter = LoopCounter + 1;

END;
Edit : Missed a bit of the MOD function out
Technical Director
www.infocat.co.uk
Post Reply