Excluding childrens from MDX set

Post Reply
biggie
Posts: 9
Joined: Wed Jul 03, 2024 9:50 am
OLAP Product: IBM TM1
Version: 2.0.88
Excel Version: 2019

Excluding childrens from MDX set

Post by biggie »

Hi!

I need help writing a correct MDX query to solve the following problem.
I have a cube 01_Confirmations with two dimensions: Departments, Stages.
Departments dimension structure:
-Dep_head (Consolidation)
--Dep_01 (C)
----Dep_01_01 (Numeric)
----Dep_01_02 (N)
--Dep_02 (C)
----Dep_02_01 (N)
----Dep_03_02 (N)
----Dep_04_03 (N)
and so on. Each consolidated Dep-element has several children. Dep_##_## is always leaf elements
Stages dimension contains two string elements ST_01, ST_02.

So, I want to create an MDX subset of elements of Departments dimension, which in the cube 01_Confirmations have the value ST_01='Confirm'. If the subset has consolidated elements (departments), then exclude all its children from the subset.
For example, in the cube 01_Confirmations value 'Confirm' set for Dep_01 (C), Dep_01_02 (N), Dep_04_03 (N). MDX should return Dep_01 and Dep_04_03. Dep_01_02 will not be included in the subset, because subset already has a Dep_01_02 parent element (Dep_01).
I wrote following filter:
FILTER([Departments].[Departments].MEMBERS, [01_Confirmation].([Stages].[Stages].[ST_01])='Confirm')
But I have no idea how to form a subset without children if their parent element is already in the subset. I tried using the EXCEPT function, but I couldn't get the correct result.

Thanks for help.
Wim Gielis
MVP
Posts: 3222
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Excluding childrens from MDX set

Post by Wim Gielis »

Can you try ?

Code: Select all

Except( Filter([Departments].[Departments].Members, [01_Confirmation].([Stages].[Stages].[ST_01]) = "Confirm"), TM1FilterByLevel( Descendants( FILTER( Filter( [Departments].[Departments].Members, [Departments].CurrentMember.Properties("ELEMENT_TYPE") = "3" ), [01_Confirmation].([Stages].[Stages].[ST_01]) = "Confirm")), 0 ))
Best regards,

Wim Gielis

IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
biggie
Posts: 9
Joined: Wed Jul 03, 2024 9:50 am
OLAP Product: IBM TM1
Version: 2.0.88
Excel Version: 2019

Re: Excluding childrens from MDX set

Post by biggie »

Wim Gielis wrote: Wed Jul 17, 2024 8:53 pm Can you try ?

Code: Select all

Except( Filter([Departments].[Departments].Members, [01_Confirmation].([Stages].[Stages].[ST_01]) = "Confirm"), TM1FilterByLevel( Descendants( FILTER( Filter( [Departments].[Departments].Members, [Departments].CurrentMember.Properties("ELEMENT_TYPE") = "3" ), [01_Confirmation].([Stages].[Stages].[ST_01]) = "Confirm")), 0 ))
Wow, nice solution. Thanks
Wim Gielis
MVP
Posts: 3222
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Excluding childrens from MDX set

Post by Wim Gielis »

You’re welcome, thanks for the feedback (it was written on the tablet without testing :D )
Best regards,

Wim Gielis

IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Post Reply