如果当前成员具有子项,则扩展用户层次结构 - MDX

时间:2013-08-05 09:48:45

标签: ssas mdx business-intelligence

我有一个用户层次结构,我想扩展和向下钻取只有用户有孩子。如果层次结构中的成员没有子节点,我想隐藏此成员。

以下查询获取所有在层级中位于第1级的人,但我只想显示那些至少有一个子成员的人。

  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]

我怎样才能做到这一点?用户层次结构是一个参差不齐的。

2 个答案:

答案 0 :(得分:2)

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]

答案 1 :(得分:0)

对于那些遇到同样问题且处于excel效果之外的人,只有父母扩展了用户层次结构的维度,这就是这样做的方法:

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]

查询将自动检查用户层次结构,并自动转到必要的级别。感谢比尔建议他的解决方案并让我走上正确的轨道。