SELF_BEFORE_AFTER - why aren't members from related levels returned?

大城市里の小女人 提交于 2020-01-16 04:11:11

问题


Here is my script:

WITH 
    SET [Set_TargetEmp] AS
        {
        FILTER(
            [Employee Department].AllMembers,
                (
                InStr(
                    1, 
                    [Employee].[Employee Department].currentmember.name, 
                    "REUBEN") <> 0
                ) 
            )
        }
SELECT
    DESCENDANTS(
        [Set_TargetEmp],
        [Employee].[Employee Department],
        SELF_BEFORE_AFTER)
    ON 1,
    {} ON 0
FROM [Adventure Works] 

I know that [Set_TargetEmp] is the following:

So why when I wrap it in the function DESCENDANTS with the optional arg SELF_BEFORE_AFTER isn't reuben's related Department and Title not returned ?


EDIT

So I've simplified the above even further. Why doesn't the following return Reuben's title and department - I thought the point of SELF_BEFORE_AFTER was to also return relatives from the other levels of the hierarchy [Employee].[Employee Department] ?

SELECT
    DESCENDANTS(
        [Employee].[Employee Department].[Employee].[Reuben H. D'sa],
        [Employee].[Employee Department],
        SELF_BEFORE_AFTER)
    ON 1,
    {} ON 0
FROM [Adventure Works] 

回答1:


Descendants only returns descendants, i. e. members on a lower level than the first argument. What you require would be an Ancestor. But - according to the documentation - the Ancestor and Ancestors functions do not allow a set as first argument. This means that - assuming your set is meant to possibly contain more than one member - you would have to use Generate to iterate over the members of [Set_TargetEmp]:

WITH 
    SET [Set_TargetEmp] AS
        {
        FILTER(
            [Employee Department].AllMembers,
                (
                InStr(
                    1, 
                    [Employee].[Employee Department].currentmember.name, 
                    "REUBEN") <> 0
                ) 
            )
        }
SELECT
    {} ON 0,
    Generate([Set_TargetEmp] as e,
             {Ancestor(e.Current, [Employee].[Employee Department].[Department])}
            )
    ON 1
FROM [Adventure Works] 


来源:https://stackoverflow.com/questions/21026900/self-before-after-why-arent-members-from-related-levels-returned

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