1
votes

I have a user hierarchy, and I would like to expand and drill down only if the user has children. If the member in the hierarchy does not have children, I would like to hide this member.

The following query gets all those who are on level 1 in the hiearchy, but I would like to show only those which have at least a child member.

  with member [Test] as '0'
SELECT
{ [Test] } ON COLUMNS, non empty
{ 
 ( 

  [Dim User].[UserHierarchy].[UserLevel1].AllMembers 

 )
}Dimension Properties MEMBER_CAPTION,
MEMBER_UNIQUE_NAME ON ROWS
FROM   [Activities]

How can I achieve this? The user hierarchy is a ragged one.

2

2 Answers

2
votes
WITH 
    MEMBER [Measures].[Test] AS
        0
SELECT
    { 
         [Test]
    } ON 0, 
    NON EMPTY { 
        FILTER (
             [Dim User].[UserHierarchy].[UserLevel1].AllMembers
            ,[Dim User].[UserHierarchy].CurrentMember.Children.Count > 0
        )
    } ON 1
FROM   [Activities]
0
votes

For others who have the same problem, and are after the excel kind of effect, where the dimension of the user hierarchy is only expanded for parents, this is the way to do it:

WITH 
    MEMBER [Measures].[Test] AS
        0
SELECT
    { 
         [Test]
    } ON 0, 
    NON EMPTY { 
        filter (
            {[dim user].[userhierarchy].[userlevel1].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel2].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel3].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel4].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel5].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel6].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel7].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel8].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel9].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        ),
        filter (
            {[dim user].[userhierarchy].[userlevel10].allmembers  }
            ,[dim user].[userhierarchy].currentmember.children.count > 1
        )
    } ON 1
FROM   [Activities]

The query will automatically check the user hierarchy, and go down to the necessary levels automatically. Thanks to Bill for suggesting his solution and putting me on the right track.