如何在MDX上求和所有常数值成员

时间:2018-10-13 02:57:43

标签: database mdx

我该如何求和总计行上一个常数成员的值。例如,此查询:

WITH 
  MEMBER [Measures].[department_code] as departments.[department_code].CurrentMember.MEMBER_CAPTION
  MEMBER [Measures].[twelve] as 12
    SELECT 
      {[Measures].[revenue],
 [Measures].[department_code],
 [Measures].[twelve]
  } ON 0,

    departments.[department_code].ALLMEMBERS
    ON 1
    FROM 
      mycube

返回此:

NULL    1000    All     12
DEPT1   600     DEPT1   12
DEPT2   400     DEPT2   12

第一行是总计,最后一行应返回24([Measure]。[十二])。

这如何完成? 谢谢

1 个答案:

答案 0 :(得分:0)

您应该对您的固定成员进行以下更改

MEMBER [Measures].[twelve] 
as 
case 
when departments.[department_code].CurrentMember.MEMBER_CAPTION='All'
then count([Product].[Product].children) * 12 
else
12
end

以下是您想要在Adventure作品中使用的示例

with member
[Measures].[ProductCode] 
as
[Product].[Product].CurrentMember.MEMBER_CAPTION
member
[Measures].[Constant] 
as
case 
when [Product].[Product].CurrentMember.MEMBER_CAPTION='All Products'
then count([Product].[Product].children) * 12 
else 
12
end

select 
{
[Measures].[Internet Sales Amount],
[Measures].[ProductCode] ,
[Measures].[Constant] 
} on 0,

[Product].[Product].members
on 1 
from [Adventure Works]