MDX - 由另一个成员值设置成员

时间:2015-08-10 11:37:12

标签: mdx olap-cube

我用MDX生成了这个表。

    http://i62.tinypic.com/2m5xeg0.jpg

我需要创建一个名为“今年”的计算维度(或度量),其中包含2个值:
  是:如果当前成员年份包括值2015和
  否:如果会员年份不包括2015年每个客户ID(
)    http://i57.tinypic.com/2h508yx.jpg

MDX代码是:

SELECT
    NON EMPTY {[Measures].[QUANTITY]} ON COLUMNS,
    NON EMPTY CrossJoin({CLIENT ID].[CLIENT ID].Members, {[YEAR].[YEAR].Members}) ON ROWS
FROM
    [MyCube]

2 个答案:

答案 0 :(得分:1)

您可以尝试以下内容:

WITH 
  MEMBER [Measures].[is2015] AS 
    IIF
    (
      Isnull(Instr(0,[YEAR].[YEAR].CurrentMember.Member_Caption,"2015"))  //<<unsure if the 2nd argumnet should read: [YEAR].CurrentMember.Member_Caption
     ,"YES"
     ,"NO"
    ) 
SELECT 
  NON EMPTY 
    {
      [Measures].[QUANTITY]
     ,[Measures].[is2015]         
    } ON COLUMNS
 ,NON EMPTY 
    CrossJoin
    (
      [CLIENT ID].[CLIENT ID].MEMBERS
     ,{[YEAR].[YEAR].MEMBERS}
    ) ON ROWS
FROM [MyCube];

以下是MSDN中使用的Instr函数的mdx文档: https://msdn.microsoft.com/en-us/library/hh758424.aspx

参考您的屏幕打印,请尝试以下方法:

WITH 
  MEMBER [Measures].[is2015] AS 
    IIF
    (
        NonEmpty
        (
          [CLIENT ID].[CLIENT ID].CurrentMember
         ,[YEAR].[YEAR].[2015]
        ).Count
      > 0
     ,"YES"
     ,"NO"
    ) 
SELECT 
  NON EMPTY 
    {
      [Measures].[QUANTITY]
     ,[Measures].[is2015]
    } ON COLUMNS
 ,NON EMPTY 
    CrossJoin
    (
      [CLIENT ID].[CLIENT ID].MEMBERS
     ,{[YEAR].[YEAR].MEMBERS}
    ) ON ROWS
FROM [MyCube];

答案 1 :(得分:1)

非常感谢!替代答案在蒙德里安完美无缺,但变化很小:

WITH 
  MEMBER [Measures].[is2015] AS 
    IIF
    (
        (
          [CLIENT ID].CurrentMember
         ,[YEAR].[2015]
        )
      > 0
     ,"YES"
     ,"NO"
    ) 
SELECT 
  NON EMPTY 
    {
      [Measures].[QUANTITY]
     ,[Measures].[is2015]
    } ON COLUMNS
 ,NON EMPTY 
    CrossJoin
    (
      [CLIENT ID].[CLIENT ID].MEMBERS
     ,{[YEAR].[YEAR].MEMBERS}
    ) ON ROWS
FROM [MyCube];