Page 1 of 1

Getting all the children of an element

Posted: Tue May 28, 2019 10:27 pm
by Rtel
Hi, In a TI, I want to loop through all the child elements of an element passed as an argument.
For eg if Element name argument to TI is 'Element 1' , TI should iterate through

Element 1.1
Element 1.2
Element 1.3
Element 1.3.1
Element 1.3.2

I tried ElementCount function, but it is throwing error as 'variable ElementCount is UNDEFINED' !!!

I tried getting count using ELCOMPN but it returns 3 for 'Element 1' (instead of 5 that I need) and I want to loop through all the children under Element 1.

If I pass 'Element B' as an argument then it should return only 'Element B' since it does not have any child element.

Logic that I thought of ..
----------------------------------------------
IF Element consolidated

Get the Count of all the children (say iAllChild)

While iCounter < iAllChild

loop thorugh all the Children using the Index

End

else

return same element

endif
----------------------------------------------

Please advise how to accomplish above or if there is a better way.

Thanks,

Rtel
--------------------------------------------------------------------
Sample Dimension

Element A
Element 1
Element 1.1
Element 1.2
Element 1.3
Element 1.3.1
Element 1.3.2
Element 2

Element B

Element C

Re: Getting all the children of an element

Posted: Tue May 28, 2019 10:51 pm
by Rtel
To add to my previous question

how to use this MDX from TI to iterate through all the elements in the subset

{TM1DRILLDOWNMEMBER( {[Dimension].[Element]}, ALL, RECURSIVE )}

Thanks

Re: Getting all the children of an element

Posted: Tue May 28, 2019 11:17 pm
by Wim Gielis
Hello,

If you have an MDX expression, you can use SubsetCreateByMDX to create a subset with said MDX, and then loop through the subset:

Code: Select all

sDim = '...';
sSub = '...';
nMax = SubsetGetSize( sDim, sSub );
nCtr = 1;
While( nCtr <= nMax );

  sEl = SubsetGetElementName( sDim, sSub, nCtr );
  # ...
  nCtr = nCtr + 1;
End;
If you don't have an MDX expression, you can loop over all dimension elements and see if they belong to the chosen element:

Code: Select all

sDim = '...';
nMax = Dimsiz( sDim );
nCtr = 1;
While( nCtr <= nMax );

  sEl = Dimnm( sDim, nCtr );
  If( Elisanc( sDim, 'the consolidated element', sEl ) = 1 );
     # ...
  EndIf;
  nCtr = nCtr + 1;
End;

Re: Getting all the children of an element

Posted: Wed May 29, 2019 10:30 am
by Drg
Rtel wrote: Tue May 28, 2019 10:51 pm To add to my previous question

how to use this MDX from TI to iterate through all the elements in the subset

{TM1DRILLDOWNMEMBER( {[Dimension].[Element]}, ALL, RECURSIVE )}

Thanks
Best solution to create dynamic subset:

Code: Select all

MDX='your mdx';
vLastDim='DimensionName';
vSubset='randomName';
SubsetCreate(vLastDim, vSubset, 1 );
SubsetMDXSet(vLastDim, vSubset, MDX );		
SubsetMDXSet(vLastDim, vSubset, '');
how to iterate subset answered Wim

Re: Getting all the children of an element

Posted: Wed May 29, 2019 2:47 pm
by samba.kesinakurthi
Hello,

You can also try the below as MDX to create the subset for your requirement

SubsetCreateByMDX(SubsetName, '{Descendants([Dimension].[Element 1])}');

Then you can loop through the subset to access the elements

Re: Getting all the children of an element

Posted: Wed May 29, 2019 3:56 pm
by Rtel
Hello All, thanks for all your help. Following is the working code that I would like to share. From the responses I understand that there are

1) two diff MDX to create subset
2) two way to create Dynamic subset

( I will try both to understand the difference)

Thanks,

Rtel


-----------------------------------------------------------------------------------------------------------------------------------------------------
sDim = 'TestMember' ;
sElement = '0246 LLC ' ;

sSubSet = ' sub_Member ' ;

SubsetCreateByMDX ( sSubSet , ' {TM1DRILLDOWNMEMBER( {[ ' | sDim | ' ].[ ' | sElement | ' ]}, ALL , RECURSIVE )} ' ) ;

nSubSetSize = SubsetGetSize( sDim, sSubSet ) ;

nSubSetCounter = 1 ;

While ( nSubSetCounter <= nSubSetSize ) ;

sEl_Member = SubsetGetElementName ( sDim, sSubSet , nSubSetCounter ) ;

Asciioutput ('test.cma', 'Element Name', sEl_Member );

# Here I intend to change one of the measure for each of these members using CellPutS

nSubSetCounter = nSubSetCounter + 1;

End;
-----------------------------------------------------------------------------------------------------------------------------------------------------

Re: Getting all the children of an element

Posted: Wed May 29, 2019 4:54 pm
by gtonkin
Glad you found a solution-was going to go ELCOMP direction but saw after posting that you had multiple levels.