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

StrToMember does not accept calculated measure (mdx)

我尝试使用一些计算的度量来创建成员(我在这里称之为 'MyDay')。我 return 在轴上与成员约会,成员有一个我想使用的 属性。我可以 return 属性 本身,但不能创建成员并使用它。

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])

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

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

如果您将 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];

以上 returns 以下:

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

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;