Quickly delete elements from a hierarchy

Ideas and tips for enhancing your TM1 application
Post Reply
Wim Gielis
MVP
Posts: 3103
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Quickly delete elements from a hierarchy

Post by Wim Gielis »

Rather than code like this:

Code: Select all

 ## Delete consolidated elements
####
iLoop=DIMSIZ(pDim);
WHILE(iLoop>=1);
  vElement=DIMNM(pDim,iLoop);
  IF(ELLEV(pDim,vElement)>=1);
    DimensionElementDelete(pDim,vElement);
  ENDIF;
  iLoop=iLoop-1;
END;

iLoop=DIMSIZ(pDim);
WHILE(iLoop>=1);
  vElement=DIMNM(pDim,iLoop);
  IF(DTYPE(pDim,vElement)@='C');
    DimensionElementDelete(pDim,vElement);
  ENDIF;
  iLoop=iLoop-1; 
END;
Consider:

Code: Select all

vDim = 'Customer';
vMDX = 'Except( TM1SubsetAll([' | vDim | ']), TM1FilterByLevel( TM1SubsetAll([ ' | vDim | ']), 0 ))';
SubsetCreateByMDX( 'tmp_', vMDX, vDim, 1 ); 
DimensionDeleteElements( vDim, 'tmp_' );
Best regards,

Wim Gielis

IBM Champion 2024
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
MarenC
Regular Participant
Posts: 346
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: Quickly delete elements from a hierarchy

Post by MarenC »

Hi Wim,

I am liking that a lot!

Maren
User avatar
gtonkin
MVP
Posts: 1192
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: Quickly delete elements from a hierarchy

Post by gtonkin »

Thanks for the tip Wim - Much quicker than the old unwinding routines most people use.
Obviously the next step is using HierarchyDeleteElements (DimensionName, HierarchyName, Subset) for hierarchies other than the default.
Wim Gielis
MVP
Posts: 3103
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Quickly delete elements from a hierarchy

Post by Wim Gielis »

MarenC wrote: Wed Sep 14, 2022 3:53 pm Hi Wim,

I am liking that a lot!

Maren
You’re welcome ! Thanks for the feedback.
Best regards,

Wim Gielis

IBM Champion 2024
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
Wim Gielis
MVP
Posts: 3103
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Quickly delete elements from a hierarchy

Post by Wim Gielis »

gtonkin wrote: Wed Sep 14, 2022 4:32 pm Thanks for the tip Wim - Much quicker than the old unwinding routines most people use.
Obviously the next step is using HierarchyDeleteElements (DimensionName, HierarchyName, Subset) for hierarchies other than the default.
True ! That part was left as an exercise for the reader :lol:
Best regards,

Wim Gielis

IBM Champion 2024
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