MDX DateAdd函数通过一组元组

时间:2014-03-25 09:08:36

标签: set tuples mdx dateadd

我正在尝试使用DateAdd()函数创建一组日期,但在尝试传递一组元组作为参数时遇到错误。 下面的代码返回一个成员,但我正在寻找一组新的日期。

  

使用       成员[EFF INJ DT] AS       DATEADD(“M”,12,[受伤日期]。现在会员)

SELECT {[EFF INJ DT]} ON COLUMNS, [INJURY DATE].[DATE].Members ON ROWS
FROM [WVWC DATA CUBE FROI SROI]

我有以下尝试:

 WITH 
Set [EFF INJ DT] AS 
DATEADD("M",12, [INJURY DATE].CurrentMember)

SELECT {[EFF INJ DT]} ON COLUMNS, [INJURY DATE].[DATE].Members ON ROWS
FROM [WVWC DATA CUBE FROI SROI]

1 个答案:

答案 0 :(得分:0)

如果您希望向前移动12名成员,则使用Adv Works,您可以通过多种方式进行导航。

尝试以下方法。它应该在currentmember之前12天返回日期:

WITH 
    MEMBER [MEASURES].[EFF INJ DT] AS
        [Date].[Calendar].CurrentMember.LEAD(12).MEMBERVALUE
SELECT 
    {[MEASURES].[EFF INJ DT]}  ON 0,
    {[Date].[Calendar].[Month].&[2006]&[4].CHILDREN} ON 1
FROM [Adventure Works];

您希望将来返回12 的日期。

首先,我们需要通过currentmember函数>对应ANCESTOR的年份。然后使用COUSIN函数前进到等效日期,如下所示:

WITH 
    MEMBER [MEASURES].[EFF INJ DT] AS
    COUSIN(
        [Date].[Calendar].CurrentMember, 
        ANCESTOR(
            [Date].[Calendar].CurrentMember, 
            [Date].[Calendar].[Calendar Year]).LEAD(1)
            ).membervalue   
SELECT 
    {[MEASURES].[EFF INJ DT]}  ON 0,
    {[Date].[Calendar].[Month].&[2006]&[4].CHILDREN} ON 1
FROM [Adventure Works];

根据您的方案并假设INJURY DATE是多级user hierarchy' that contains another level called日历年',您可以执行以下操作:

WITH 
    MEMBER [MEASURES].[EFF INJ DT] AS
        COUSIN(
            [INJURY DATE].CurrentMember, 
            ANCESTOR(
                [INJURY DATE].CurrentMember, 
                [INJURY DATE].[Calendar Year]).LEAD(1)
                ).MEMBERVALUE   
SELECT 
    {[MEASURES].[EFF INJ DT]}  ON 0,
    {[INJURY DATE].[DATE].Members} ON 1
FROM [Adventure Works];

编辑

通过VBA工具,我们在Adv Wrks中有以下内容:

WITH 
    MEMBER [MEASURES].[EFF INJ DT] AS
      DATEADD(
      "M",
      12,
      [Date].[Calendar].CurrentMember.membervalue 
      )  
SELECT 
    {[MEASURES].[EFF INJ DT]}  ON 0,
    {[Date].[Calendar].[Month].&[2006]&[4].CHILDREN} ON 1
FROM [Adventure Works];

适应您的情况:

WITH 
    MEMBER [MEASURES].[EFF INJ DT] AS
    DATEADD(
    "M",
    12,
    [INJURY DATE].CurrentMember.membervalue 
    )  
SELECT 
    {[MEASURES].[EFF INJ DT]}  ON 0,
    {[INJURY DATE].[DATE].Members} ON 1
FROM [Adventure Works];