Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Jul 9, 2003

MDX Essentials - MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions - Page 4

By William Pearson

The PeriodsToDate() Shortcut Functions

As we learned above, the PeriodstoDate() function is used within the following basic syntax:

PeriodsToDate([«Level»[, «Member»]])

Several "shortcut functions" are available in MDX to allow us to perform time-based summaries on period-to-date levels. Among these levels are the following, displayed in Table 1, that correspond to common levels of measurement in the business environment, together with the associated, specialized shortcut function that exists in MDX.

Level of Measurement

Shortcut Function

Year to Date


Quarter to Date


Month to Date


Week to Date


Table 1: The PeriodToDate() Shortcut Functions


The above functions are equivalent to the PeriodsToDate() function, with the appropriate levels fixed for the specialized context within which each might be used. A composite of the syntax that each uses in the sample cube is as follows:

PeriodsToDate([Year] | [Quarter] | [Month] | [Week] , [«Member»]])

Because the syntax is similar to all the shortcut functions, and because the operation of each is identical, with the exception of the specific levels involved, we will examine one sample of the group to confirm our understanding of general concepts. To this end, let's examine the QTD() function specifically.

Syntax - QTD() Function

As is the case with each member of the set of shortcut functions listed in Table 1 above, the QTD () function is a shortcut function derived from the PeriodsToDate () function. The QTD() function defines the PeriodsToDate () function's «Level» argument to be Quarter. If no member is specified, the default is Time.CurrentMember. In short, therefore:

Qtd ([«Member»])

is equivalent to

PeriodsToDate(Quarter, «Member»)

The following example returns the set of members from the beginning of the Quarter level in the Time dimension, from the ancestor of Time.CurrentMember , through Time.CurrentMember:


Characteristically for all PeriodsToDate() derivatives, if no member is specified, the default is Time.CurrentMember.


Let's practice with the QTD() function, combining its use with that of a calculated member, in a manner that assists us in performing analysis of performance from one year to the next. We will rejoin the MDX Sample Application, creating a new query for the purposes of this exercise.

8.             Select File --> New from the top menu of the MDX Sample Application.

9.             Ensure that FoodMart 2000 is selected as the database name in the DB box of the toolbar, and that the HR cube remains selected in the Cube drop-down list box.

10.         Type the following query into the Query pane:

-- MDX09-3:  Tutorial Query No. 3
   MEMBER [Measures].[QTD Salaries] AS
   'Sum(QTD(),[Org Salary])'
   {[Measures].[Org Salary] , [Measures].[QTD Salaries]} ON COLUMNS,  
     [Time].[Month].Members ON ROWS

11.         Select Query --> Run from the top menu to execute the query.

The query runs and the result dataset appears, as shown in Illustration 5.

Illustration 5: The Query Result Dataset

The query delivers the results as requested; we see the results above to be identical to those shown in Illustration 4 above. The reason is simple - we have substituted the QTD() function for


in the previous example, primarily to illustrate that the two functions deliver the identical result. QTD() is, as we have learned, a shortcut function for the PeriodsToDate() function with the «Level» argument set to Quarter. We thus prove the fact that the functions are equal by substituting the shortcut QTD() for PeriodsToDate().

The remaining shortcut functions behave in a similar manner.

We can easily see the utility of the shortcut functions for cases where the <<level>> argument, such as Quarter in our last example, can be predefined. Again, if no member is specified in the argument, the default is fixed as Time.CURRENTMEMBER by MDX.

Next in Our Series ...

In this lesson, we introduced the time series functions group, a specialized group of time series functions that MDX provides to perform analysis within the context of time. After discussing the common business need to analyze data over time, we overviewed the PeriodsToDate() function in detail, illustrated the syntax that is appropriate for its effective use, and then tested our understanding of how to leverage this important time series function by undertaking a relevant practice exercise.

As part of our use of the PeriodsToDate() function, we revisited the construction of a calculated member, using a calculated measure as a vehicle for illustration of the operation of the PeriodsToDate() function. We introduced the Sum statement as a part of building the calculated member, and discussed its constituent parts, as well. (We will revisit the Sum function many times as we progress in our series.) We then discussed the specialized "shortcut" functions that are based upon PeriodsToDate(), including the YTD(), QTD(), MTD(), and WTD() functions.

In our next lesson, we will introduce two additional time series functions, OPENINGPERIOD() and CLOSINGPERIOD(). Next, we will conclude our three-article time series functions group with an examination of the LASTPERIODS() and PARALLELPERIODS() functions.

» See All Articles by Columnist William E. Pearson, III

Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum.

MS SQL Archives

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM