可以在层次结构和维度属性之间进行CROSSJOIN吗?

时间:2018-06-22 10:17:14

标签: ssas mdx

我目前正在使用MDX显示代理分支层次结构的后代,直到代理名称级别:

UNION (
{DESCENDANTS ([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Retail],5,SELF_AND_BEFORE) }
,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Digital],5, SELF_AND_BEFORE)}        
,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Telesales],5, SELF_AND_BEFORE)}  
,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Head Office],5, SELF_AND_BEFORE)} 
)

但是,我想在代理人名称旁边显示AgentEmployeeNumberAgentEmployeeNumber不是AgentBranch Hierarchy的一部分,而且我似乎找不到一种将两者交叉连接的方式,这有可能吗?我在下面提供了代理维度的结构片段:

Agent Dimension

1 个答案:

答案 0 :(得分:0)

您可以为这样的行使用交叉联接(缩写为*):

SELECT
    {} // add whatever you want, I assume you have measures here
    ON COLUMNS,
    UNION (
        {DESCENDANTS ([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Retail],5,SELF_AND_BEFORE) }
        ,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Digital],5, SELF_AND_BEFORE)}        
        ,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Telesales],5, SELF_AND_BEFORE)}  
        ,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Head Office],5, SELF_AND_BEFORE)} 
    )
    *
    [Agent].[Agent Employee Number].[Agent Employee Number].Members
ON ROWS
FROM [Your Cube]

缺点是,对于Agent Branch Hierarchy成员(不在单个代理程序级别上),您将获得很多数字。解决此问题的一种方法是将计算得出的度量放在列中:

WITH MEMBER Measures.[Employee Number] AS
     IIf(
         (EXISTING [Agent].[Agent Employee Number].[Agent Employee Number].Members).Count = 1,
         (EXISTING [Agent].[Agent Employee Number].[Agent Employee Number].Members).Item(0).Item(0).Name,
         NULL
     )
SELECT
    Measures.[Employee Number] // add whatever you want, I assume you have measures here
    ON COLUMNS,
    UNION (
        {DESCENDANTS ([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Retail],5,SELF_AND_BEFORE) }
        ,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Digital],5, SELF_AND_BEFORE)}        
        ,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Telesales],5, SELF_AND_BEFORE)}  
        ,{DESCENDANTS([Agent].[Agent Branch Hierarchy].[Agent Business Division].&[Head Office],5, SELF_AND_BEFORE)} 
    )
ON ROWS
FROM [Your Cube]

成员定义或多或少地声明:“如果当前Agent Branch Hierarchy成员的一组雇员编号中只有一个元素,则将第一个(也是唯一一个)元素的名称作为度量值。请注意,已计算的度量可以返回字符串,不必一定是数字。