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

后端 未结 1 457
野的像风
野的像风 2021-01-24 07:44

We have a user hierarchy with 3 levels (Level1 being the upper level - Level3 the lower)

Using the FILTER function I state a string, this strin

1条回答
  •  囚心锁ツ
    2021-01-24 07:51

    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.

    0 讨论(0)
提交回复
热议问题