Hi just after some tips for the best way to clean up a dimension with multiple hierarchies.
I’m using TI to create a number of additional hierarchies based on attributes:
Code: Select all
IF (PContract@='');
PContract= 'Unspec Contract';
ENDIF;
IF (DIMIX(DimName,PContract)=0);
DimensionElementInsert(DimName, '', PContract, 'C');
DimensionElementComponentAdd(DimName, 'Total Project ID by Contract', PContract, 1);
ENDIF;
DimensionElementComponentAdd(DimName, PContract, ElName, 1);
Total Project ID by Contract
AttributeA
- Project 1
Project 3
- Project 1
Project 2
This is because I want to unwind my hierarchy but not the other hierarchies in the system
I created TI that looks up the parent sees if it’s one I’m interested in then finds the children and removes them from the dimension see below:
Code: Select all
vIndex = 1;
vElParN = ELPARN(DimName, Project_ID);
While (vIndex<=vElParN);
vElPar = ELPAR (DimName, Project_id, vindex);
## This code is to unwind the project hierarchies but only for the project hierarchies we are creating in Dim Project ID 7. Consolidation by Class
## This is because the TI there adds into the hierarchy but does not delete redundant ones
## Added by James Webber IRL 120427 see TMI-241
## Based on Ben Hills Example http://blog.tm1tutorials.com/tag/dimensionelementcomponentdelete/
# Frist lets check to see if the Parent of the project is total contract
If (vElpar @= 'Total Project ID by Contract');
# Now how many children are there underneath?
ChildCount = ELCOMPN(DimName, Project_Id);
# find the name of each of the children
WHILE(ChildCount > 0);
sChildElm = ELCOMP(DimName, Project_Id,ChildCount);
#Now check the child name is an ancestor (child) of the project_ID, i.e the node in this case
#IF (ELISANC(DimName, Project_Id, sChildElm) = 1);
# If so remove it from the hierarchy
DimensionElementComponentDelete(DimName, Project_Id, sChildElm);
#ENDIF;
ChildCount = ChildCount - 1;
end;
ENDIF;
vElParN = vElParN-1;
END;
This works but does anyone know of a more elegant way to find out all elements under an alternative hierarchy and remove these entries from the dimension?
I.e. is there a more elegant way of doing this?