Search AllMembers of User Hierarchy - for corresponding Set return a related members from upper and lower levels

折月煮酒 提交于 2019-12-02 07:33:33

I suppose a similar query on AdventureWorks delivers what you want:

WITH 
   MEMBER [Measures].[LevelName] AS
       [Employee].[Employee Department].CurrentMember.Level.Name
   MEMBER [Measures].[LevelNumber] AS
       [Employee].[Employee Department].CurrentMember.Level.Ordinal
   MEMBER [Measures].[MemName] AS
       [Employee].[Employee Department].CurrentMember.Name
   SET [Set_TargetEmp] AS
        {
        FILTER(
            [Employee Department].AllMembers,
                (
                InStr(
                    1, 
                    [Employee].[Employee Department].currentmember.name, 
                    "WC4") <> 0
                ) 
            )
        }
SELECT
    {
    [Measures].[MemName], 
    [Measures].[LevelName],
    [Measures].[LevelNumber] 
    } ON 0,
    Hierarchize(
        Generate([Set_TargetEmp] as e,
            Ascendants(e.Current)
            +
            Descendants(e.Current, e.Current.Level, SELF_AND_AFTER)
        )
    )
    ON 1
FROM [Adventure Works] 

I used Hierarchize to sort the result by hierarchy, as that seemed the most easy way for me to check the result. You may want to change that. As - in contrast to the Descendants method - Ascendants does not allow a set as the first argument, I used Generate to iterate along the set. Its default behavior (without a third argument of All), it eliminates duplicates, which I assumed is the behavior you need.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!