StrToMember不接受计算的度量(mdx)

时间:2015-04-14 14:08:01

标签: mdx

我尝试使用一些计算出的度量来创建成员(我在这里称之为“MyDay”)。我在轴上返回日期成员,成员有一个我想要使用的属性。我可以返回属性本身,但不能创建成员并使用它。

WITH
MEMBER [Measures].[MyDay] as DatePart("d", MyDateDimension.CurrentMember.Properties("MyProperty"))

MEMBER MyDateDimension.[MyMember] AS  
    STRTOMEMBER("MyDateDimension.&[2015]&[4]&[" + CStr([Measures].[MyDay]) + "]")

MEMBER [Measures].[SomeOther] as (MyDateDimension.[MyMember], [Measures].[Other]

SELECT
{ 
    MyDateDimension.Members)

} ON COLUMNS,

{
    [Measures].[MyDay] //works,
    [Measures].[SomeOther] //error
}

如果我用某个硬编码日期成员替换'MyDateDimension.CurrentMember', 它工作正常。 这也有效:

MEMBER [Measures].[SomeOther] as (STRTOMEMBER("MyDateDimension.&[2015]&[4]&[" + CStr([Measures].[MyDay]) + "]"), [Measures].[Other])

2 个答案:

答案 0 :(得分:1)

如果你将strToMember直接放在SomeMeasure中,那么事情就会开始起作用:

WITH 
  MEMBER [Measures].[MyDay] AS 
    Datepart
    ("d"
     ,[Date].[Calendar].CurrentMember.Member_Caption
    ) 
  MEMBER [Date].[Calendar].[MyMember] AS 
    StrToMember
    (
      '[Date].[Calendar].&[200603' + Cstr([Measures].[MyDay]) + ']'
     ,constrained
    ) 
  MEMBER [Measures].[SomeOther] AS 
    (
      //[Date].[Calendar].[MyMember]
      StrToMember
      (
        '[Date].[Calendar].&[200603' + Cstr([Measures].[MyDay]) + ']'
       ,constrained
      )
     ,[Measures].[Internet Sales Amount]
    ) 
SELECT 
  {
    [Measures].[MyDay]
   ,[Measures].[SomeOther]
  } ON COLUMNS
 ,Tail
  (
    Descendants
    (
      [Date].[Calendar].[Month].&[2005]&[8]
     ,[Date].[Calendar].[Date]
    )
   ,10
  ) ON ROWS
FROM [Adventure Works];

稍微整洁的版本:

WITH 
  MEMBER [Measures].[MyDay] AS 
    Datepart
    ("d"
     ,[Date].[Calendar].CurrentMember.Member_Caption
    ) 
  MEMBER [Measures].[MyDayString] AS 
    '[Date].[Calendar].&[200603' + Cstr([Measures].[MyDay]) + ']' 
  MEMBER [Measures].[SomeOther] AS 
    (
      StrToMember
      (
        [Measures].[MyDayString]
       ,constrained
      )
     ,[Measures].[Internet Sales Amount]
    ) 
SELECT 
  {
    [Measures].[MyDay]
   ,[Measures].[SomeOther]
  } ON COLUMNS
 ,Tail
  (
    Descendants
    (
      [Date].[Calendar].[Month].&[2005]&[8]
     ,[Date].[Calendar].[Date]
    )
   ,10
  ) ON ROWS
FROM [Adventure Works];

上面返回以下内容:

enter image description here

你的立方体中有这样的东西:

WITH 
  MEMBER [Measures].[MyDay] AS 
    Datepart
    ("d"
     ,MyDateDimension.CurrentMember.Properties("MyProperty")
    ) 
  MEMBER [Measures].[MyDayString] AS 
    StrToMember('MyDateDimension.&[2015]&[4]&[' + Cstr([Measures].[MyDay]) + ']') 
  MEMBER [Measures].[SomeOther] AS 
    (
      StrToMember
      (
        [Measures].[MyDayString]
       ,constrained
      )
     ,[Measures].[Other]
    ) 
SELECT 
  {
    [Measures].[MyDay]
   ,[Measures].[SomeOther]
  } ON COLUMNS
 ,{MyDateDimension.MEMBERS} ON ROWS
FROM YourCube;

答案 1 :(得分:0)

尝试使用SUM定义中的[Measures].[SomeOther]函数。它将接受计算成员。

MEMBER [Measures].[SomeOther] as 
SUM(
   MyDateDimension.[MyMember], 
   [Measures].[Other]
   )