DateRoll

To the given date, 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 )
ParameterDescription

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,

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