Page 1 of 1

Quickly delete elements from a hierarchy

Posted: Wed Sep 14, 2022 2:26 pm
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_' );

Re: Quickly delete elements from a hierarchy

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

I am liking that a lot!

Maren

Re: Quickly delete elements from a hierarchy

Posted: Wed Sep 14, 2022 4:32 pm
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.

Re: Quickly delete elements from a hierarchy

Posted: Wed Sep 14, 2022 5:03 pm
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.

Re: Quickly delete elements from a hierarchy

Posted: Wed Sep 14, 2022 5:03 pm
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: