DatePart
The MDX DatePart function for Essbase returns a numeric representation of a date component, which can be the year, quarter, month, week, day, day of year, or day of week.
This function returns the Year/Quarter/Month/Week/Weekday/DayOfYear/Day as a number, given the input date and a date part, following the standard Gregorian calendar.
Syntax
DatePart ( date, date_part_ex )
Parameters
- date
-
A number representing the input date. 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(), or DateRoll().
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_ex
-
Defined time components as per the standard calendar.
-
DP_YEAR - Year of the input date, in
yyyy
format. -
DP_QUARTER - Quarter of the year (1 to 4) for the input date.
-
DP_MONTH - Month of the year (1 to 12) for the input date.
-
DP_WEEK - Week of the year for the input date (1 to 54).
-
DP_DAY - Day of the month for the input date (1 to 31).
-
DP_WEEKDAY returns the week day of the input date. (1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday, 7 = Saturday).
-
DP_DAYOFYEAR - Day of the year numbering (1 to 366).
-
Notes
Example: For June 14, 2024,
DP_YEAR
returns 2024 (the year member, in yyyy
format).
DP_QUARTER
returns 2 (Second quarter of the year)
DP_MONTH
returns 6 (Sixth month of the year)
DP_WEEK
returns 24 (24th week of the year)
DP_WEEKDAY
returns 4 (for Wednesday. Sunday = 1)
DP_DAYOFYEAR
returns 165 (165th day of the year)
DP_DAY
returns 14 (14th day of the month)
Example
The following query returns the quarterly sales for the second quarter across all years for the product Cola in the market California.
SELECT
{[Sales]}
ON COLUMNS,
{
Filter(
[Time dimension].Quarters.members,
Datepart(
getFirstDate([Time dimension].CurrentMember),
DP_QUARTER
) = 2
)
}
ON ROWS,
FROM MySamp.Basic
WHERE (Actual, Cola, California);