Dynamic Subset using MDX

Post Reply
sathishh.mk
Posts: 38
Joined: Mon Dec 20, 2010 5:02 am
OLAP Product: Cognos TM1
Version: 9.4 and 9.5
Excel Version: 2003 and 2007

Dynamic Subset using MDX

Post by sathishh.mk »

Hi,

I am trying to create dynamic subset using below MDX,but it is not working.
Need suggestions on this.

SubsetCreateByMDX('WaferSize_Item',ELPAR('Product_Dim','{FILTER( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Product_Dim] )}, 0)}, [Product_Dim].[SIZE] = "200")}'), 1));

Here "200" is Attribute value of products and wants replace with user input variable.


Regards,
Sathish
declanr
MVP
Posts: 1831
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Dynamic Subset using MDX

Post by declanr »

sathishh.mk wrote:Hi,

I am trying to create dynamic subset using below MDX,but it is not working.
Need suggestions on this.

SubsetCreateByMDX('WaferSize_Item',ELPAR('Product_Dim','{FILTER( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Product_Dim] )}, 0)}, [Product_Dim].[SIZE] = "200")}'), 1));

Here "200" is Attribute value of products and wants replace with user input variable.


Regards,
Sathish
The ELPAR section of your code isn't MDX and the subsetcreatebymdx function only accepts an mdx statement so that won't work. I can't remember off the top of my head how you get element parents in MDX but the following should work.

Code: Select all


SubsetCreateByMDX ( 'WaferSize_Item_temp', sMDX, sDimName );
SubsetCreate ( sDimName, 'WaferSize_Item' );
iCount = 1;
iMax = SubsetGetSize ( sDimName, 'WaferSize_Item_Temp' );
While ( iCount <= iMax );
              sElement = SubsetGetElementName ( sDimName, 'WaferSize_Item_Temp', iCount );
              sParent = ElPar ( sDimName, sElement, 1 );
              If ( sParent @<> '' );
                            SubsetElementInsert ( sDimName, 'WaferSize_Item', sParent, SubsetGetSize ( sDimName, 'WaferSize_Item' ) + 1 );
              EndIf;
              iCount = iCount + 1;
End;
SubsetDestroy ( sDimName, 'WaferSize_Item' );
Note that the third MDX statement parameter is only applicable in versions 10.1 and above. And sMDX is your MDX statement, make the 200 part parameter dependent and get rid of the elpar.
Declan Rodger
mvaspal
Community Contributor
Posts: 341
Joined: Wed Nov 03, 2010 9:16 pm
OLAP Product: tm1
Version: 10 2 2 - 2.0.5
Excel Version: From 2007 to 2013
Location: Earth

Re: Dynamic Subset using MDX

Post by mvaspal »

Hi
I'm not sure ELPAR works in an MDX statement. Try "parent" instead.
Second comment: what if the FILTER returns more than one element as result? I think the 'Parent' function needs one element of which you want to query the parent.

UPDATE: just reading through the post of declanr - this is a fine solution as it also resolves the problem if in the filter you receive elements of which parents are not the same.
declanr
MVP
Posts: 1831
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Dynamic Subset using MDX

Post by declanr »

mvaspal wrote:Hi
I'm not sure ELPAR works in an MDX statement. Try "parent" instead.
That's the one I was trying to think of (and it couldn't have been a more obviously named one :oops: ), the benefit of MDX of course as opposed to my while loop method is that it will constantly update when extra elements appear etc.
Declan Rodger
Post Reply