Domanda

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]
È stato utile?

Soluzione

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];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top