The below code proposal is not just limited to deleting elements to unwind a dimension, you should view this contribution in a broader sense. For instance, deleting elements that don't have data in a certain cube and are marked with a certain attribute. Loops are not necessary and can be replaced by a neat and elegant MDX solution together with 1 line of code to delete the returned elements.
Rather than typical code like this:## 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:
vDim = 'Customer';
vMDX = 'Except( TM1SubsetAll([' | vDim | ']), TM1FilterByLevel( TM1SubsetAll([ ' | vDim | ']), 0 ))';
SubsetCreateByMDX( 'tmp_', vMDX, vDim, 1 );
DimensionDeleteElements( vDim, 'tmp_' );
Much more elegant, clean and it often completes (much) quicker.
Refer to this new
article
------------------------------
Wim Gielis
------------------------------
#PlanningAnalyticswithWatson