CURRENTMEMBER没有涵盖一组日期

时间:2014-04-22 12:54:45

标签: sql-server ssas mdx

我在MDX中有这个脚本:

WITH 
MEMBER [Measures].[FirstDay] as
 HEAD (
  DESCENDANTS ( 
     [Date].[Date - Calendar Month].CURRENTMEMBER, 
     [Date].[Date - Calendar Month].[Calendar Day] )
  , 1
 ).ITEM( 0 ).member_value
MEMBER [Measures].[LastDay] as
 TAIL (
  DESCENDANTS ( 
     [Date].[Date - Calendar Month].CURRENTMEMBER, 
     [Date].[Date - Calendar Month].[Calendar Day] )
  , 1
 ).ITEM( 0 ).member_value
SELECT
  { 
   [Measures].[FirstDay], 
   [Measures].[LastDay] 
  }  ON COLUMNS
FROM [OurCube]
WHERE
  ({[Date].[Date - Calendar Month].[Calendar Year].&[2012], 
    [Date].[Date - Calendar Month].[Calendar Year].&[2013]})

问题是我试图将WHERE子句中的2012和2013结合起来作为一个集合:然后将其用作评估自定义中CURRENTMEMBER函数的上下文度量 - 但此函数需要成员而不是集合。

如何更改脚本以使其返回01 Jan 201231 Dec 2013 ,而不在行或列上包含维[Date]

1 个答案:

答案 0 :(得分:1)

WITH 
MEMBER [Measures].[FirstDay] as
 (
  EXISTING  [Date].[Date - Calendar Month].[Calendar Day].Members
 ).ITEM( 0 ).member_value
MEMBER [Measures].[LastDay] as
 TAIL (
  EXISTING  [Date].[Date - Calendar Month].[Calendar Day].Members
  , 1
 ).ITEM( 0 ).member_value
SELECT
  { 
   [Measures].[FirstDay], 
   [Measures].[LastDay] 
  }  ON COLUMNS
FROM [OurCube]
WHERE
  ({[Date].[Date - Calendar Month].[Calendar Year].&[2012], 
    [Date].[Date - Calendar Month].[Calendar Year].&[2013]})

应该提供。我稍微简化了第一个计算:由于ITEM(0)已经占用了第一个元组,因此无需使用HEAD(..., 1)

请参阅http://sqlblog.com/blogs/mosha/archive/2007/01/13/multiselect-friendly-mdx-for-calculations-looking-at-current-coordinate.aspx以及第一句中引用的前一篇文章,了解"多选友好MDX"来自SSAS的一位开发人员。