MDX DateAdd function over a set of tuples

梦想的初衷 提交于 2019-12-11 15:06:20

问题


I am trying to create a set of dates using DateAdd() function but I am getting errors while trying to pass a set of tuples as parameter. The below code returns a member but I am looking for a set of new dates.

WITH Member [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]

I have the following attempt:

 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:


Using Adv Works if you want to move 12 members forward then you can navigate in several ways.

Try the following. It should return the date 12 days ahead of the currentmember:

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

Looks like you want to return the date which is 12 months in the future.

So first we need the year that corresponds to the currentmember via the ANCESTOR function > then go forward to the equivalent date using the COUSIN function like the following:

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

Adapting to your scenario and assuming that INJURY DATE is a multi-level user hierarchy' that contains another level calledCalendar Year` you could do the following:

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

EDIT

Via the VBA tools we have the following in 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];

Adapted to your scenario:

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


来源:https://stackoverflow.com/questions/22629814/mdx-dateadd-function-over-a-set-of-tuples

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!