简体   繁体   中英

How filter only the children members in MDX?

When I run this mdx query, works fine (get the children members from a hierarchy level):

select {} on columns,
[Dimension].[hierarchy].[level].children on rows
from [Cube]

But, when I add some tuple on rows, doesn't filter filter the children members (shows all the members) :S

select {} on columns,
[Dimension].[hierarchy].[level].children 
* [Dimension2].[hierarchy2].[level2].allmembers on rows
from [Cube]

* is a cross join - you will get the Cartesian product of [Dimension].[hierarchy].[level].children and [Dimension2].[hierarchy2].[level2].allmembers because they are different dimensions.

If they were two hierarchies from the same dimension then auto exist behaviour would limit the results eg Year2014 crossed with month should just show the months in 2014.

Try using DESCENDANTS function + you might not require NULLs so try the NON EMPTY

SELECT
  {} ON COLUMNS,
  NON EMPTY
  DESCENDANTS(
    [Dimension].[hierarchy].[level].[PickAHigherUpMember],
    [Dimension].[hierarchy].[PickTheLevelYouWantToDrillTo]
    ) 
  * 
  [Dimension2].[hierarchy2].[level2].allmembers ON ROWS
FROM [Cube]

if you look at the mdx language reference for children, you will also find another example of how to use the function with a hierarchy in stead of a member_expression.

http://msdn.microsoft.com/en-us/library/ms146018.aspx

but it won't work with a hierarchy level.

Maybe the row expression was initialy a hierarchy that you've have changed into a level expression.

in the following a similar working mdx with a hierarchy on rows:

select {} on 0,
[Product].[Model Name].children
*
[Geography].[Country].[All Geographies]
 on 1
FROM [Adventure Works

Philip,

I guess you want only those rows where the children have a value on the default measure. In that case you could try the following:

select {} on columns,
Nonempty([Dimension].[hierarchy].[level].children 
* [Dimension2].[hierarchy2].[level2].allmembers) on rows
from [Cube]

Now if, for the children, you'd need all the members from Dimension2 then you could try:

select {} on columns,
Nonempty([Dimension].[hierarchy].[level].children, [Dimension2].[hierarchy2].[level2].allmembers)
* [Dimension2].[hierarchy2].[level2].allmembers) on rows
from [Cube]

In the second case the Nonempty function takes a second parameter and the cross join is done with the result of the Nonempty function. For the documentation on Nonempty including the usage of the second parameter see https://docs.microsoft.com/en-us/sql/mdx/nonempty-mdx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM