DateRoll

The MDX DateRoll function for Essbase adds/subtracts time intervals to/from a date.

To the given date, this function rolls (adds or subtracts) a number of specific time intervals, returning another date. This function assumes a standard Gregorian calendar.

Syntax

DateRoll ( date, date_part, number )

Parameters

date

A number representing the date between January 1, 1970 and Dec 31, 2037. The number is the number of seconds elapsed since midnight, January 1, 1970. To retrieve this number, use any of the following functions: Today(), TodateEx(), GetFirstDate(), GetLastDate().

Date-time attribute properties of a member can also be used to retrieve this number. For example,

  • Product.currentmember.[Intro Date] returns the product introduction date for the current product in context.

  • [Cola].[Intro Date] returns the product introduction date for Cola.

date_part

Defined time components as per the standard calendar.

  • DP_YEAR - Year of the input date.

  • DP_QUARTER - Quarter of the input date.

  • DP_MONTH - Month of the input date.

  • DP_WEEK - Week of the input date.

  • DP_DAY - Day of the input date.

number

Number of time intervals to add or subtract.

Notes

Based on input date_part and dateroll number, the date is moved forward or backward in time.

Example: For input date June 14, 2005 and input dateroll number 5,

  • DP_YEAR adds 5 years to the input date. (June 14, 2010)

  • DP_QUARTER adds 5 quarters to the input date. (June 14, 2005 + 5 quarters = June 14, 2005 + 15 months = Sept 14, 2006)

  • DP_MONTH adds 5 months to the input date (June 14, 2005 + 5 months = Nov 14, 2005)

  • DP_WEEK adds 5 weeks to the input date (June 14, 2005 + 5 weeks = June 14, 2005 + 35 days = July 19, 2005)

  • DP_DAY adds 5 days to the input date. (June 14, 2005 + 5 days = June 19, 2005)

Example

The following query returns actual weekly sales, rolling back for six months from Apr 2005 (inclusive), for the product Cola in the market California.

SELECT 
 {[Sales]} 
ON COLUMNS,
 {DateToMember
  (
   DateRoll(
     GetFirstDate ([Apr 2005]),
         DP_MONTH,
         6
   ),
   [Time dimension].Dimension, 
   [Time dimension].[WEEKS]
   ): ClosingPeriod([Time dimension].[Weeks], [Apr 2005]))
  } ON ROWS
FROM MySamp.Basic
Where (Actual, California, Cola);