在计算成员中使用 EXCEPT

Jam*_*iec 3 ssas mdx

我在 MDX 查询中有以下计算成员:

MEMBER [Asset].[Class].[Fixed Income Derivatives (Inflation Linked)]
AS
(
    [Asset].[Class].&[Fixed Income],
    [Asset].[Sub Class].&[Derivatives],
    [Asset].[Sub Class Type].&[Inflation]
)
Run Code Online (Sandbox Code Playgroud)

这在查询中使用如下:

SELECT
{
  [Measures].[Market Value]
} ON 0,
NON EMPTY(
{ 
    [Asset].[Class].[Fixed Income Derivatives (Inflation Linked)]
} ON 1
FROM [Asset]
Run Code Online (Sandbox Code Playgroud)

这很好用,当然也给了我所有与通货膨胀挂钩的固定收益衍生品的市场价值。

我现在尝试添加第二个计算成员,这次给我的所有固定收益derviatives这是不是通货膨胀挂钩。我虽然这会像EXCEPT第二个成员一样简单:

MEMBER [Asset].[Class].[Fixed Income Derivatives (Non Inflation Linked)]
AS
(
    [Asset].[Class].&[Fixed Income],
    [Asset].[Sub Class].&[Derivatives], 
    EXCEPT(
       [Asset].[Sub Class Type].[Sub Class Type], 
       [Asset].[Sub Class Type].&[Inflation]
    )
)
Run Code Online (Sandbox Code Playgroud)

唉,不走运 - 它产生了错误

该函数需要参数的字符串或数字表达式。使用了元组集表达式。

这是一个令人困惑的消息,但对于 SSAS 中的课程来说是标准的。我确定我在正确的轨道上,只是有一点点错误,但我一生都无法发现问题。

小智 5

您只需要使用 Aggregate 函数来实现您的目标而不会出错。

如下更改您的计算成员定义;

MEMBER [Asset].[Class].[Fixed Income Derivatives (Non Inflation Linked)]
AS
(
    Aggregate
    (
       {[Asset].[Class].&[Fixed Income]} * 
       {[Asset].[Sub Class].&[Derivatives]} * 
       EXCEPT
       (
        [Asset].[Sub Class Type].[Sub Class Type], 
        [Asset].[Sub Class Type].&[Inflation]
       )
       ,Measures.CurrentMember
    )
)
Run Code Online (Sandbox Code Playgroud)