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

July 8, 2003

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

YTD()

Quarter to Date

QTD()

Month to Date

MTD()

Week to Date

WTD()

Table 1: The PeriodToDate() Shortcut Functions

Discussion

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:

Qtd()

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

Practice

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
WITH 
   MEMBER [Measures].[QTD Salaries] AS
   'Sum(QTD(),[Org Salary])'
SELECT 
   {[Measures].[Org Salary] , [Measures].[QTD Salaries]} ON COLUMNS,  
     [Time].[Month].Members ON ROWS
FROM HR

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

(PeriodsToDate([Time].[Quarter])

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.

MDX Essentials Series
The LEVEL_NUMBER Member Property
The LEVEL_UNIQUE_NAME Intrinsic Member Property
Intrinsic Member Properties: The HIERARCHY_UNIQUE_NAME Property
Intrinsic Member Properties: The DIMENSION_UNIQUE_NAME Property
Further Combination of BottomCount() with Other MDX Functions
Combine BottomCount() with Other MDX Functions to Add Sophistication
Basic Set Functions: The BottomCount() Function, Part I
Intrinsic Member Properties: The MEMBER_VALUE Property
Intrinsic Member Properties: The MEMBER_UNIQUE_NAME Property
Intrinsic Member Properties: The MEMBER_NAME Property
Intrinsic Member Properties: The MEMBER_KEY Property
Intrinsic Member Properties: The MEMBER_CAPTION Property
Set Functions: The StripCalculatedMembers() Function
Set Functions: The AddCalculatedMembers() Function
MDX Numeric Functions: The Min() Function
MDX Numeric Functions: The Max() Function
Set Functions: The .AllMembers Function
MDX Essentials: Set Functions: The MeasureGroupMeasures() Function
String Functions: The .Properties Function, Part II
String Functions: The .Properties Function
Logical Functions: IsGeneration(): Conditional Logic within Filter Expressions
MDX Scripting Statements: Introducing the Simple CASE Statement
Logical Functions: IsGeneration(): Conditional Logic within Calculations
Logical Functions: IsAncestor(): Conditional Logic within Filter Expressions
MDX Clauses and Keywords: Use HAVING to Filter an Axis
Logical Functions: IsAncestor(): Conditional Logic within Calculations
Logical Functions: IsSibling(): Conditional Logic within Filter Expressions
Logical Functions: IsSibling(): Conditional Logic within Calculations
MDX Operators: The IsLeaf() Operator: Conditional Logic within Filter Expressions
MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations
MDX Numeric Functions: The .Ordinal Function
Other MDX Entities: Perspectives
MDX Operators: The IS Operator
MDX Set Functions: The Distinct() Function
MDX Set Functions: The ToggleDrillState() Function
Set Functions: The DrillUpLevel() Function
Set Functions: The DrillDownLevelTop() and DrillDownLevelBottom() Functions
MDX Set Functions: DrillDownLevel()
MDX Set Functions: The DRILLUPMEMBER() Function
MDX Essentials: Set Functions: The DRILLDOWNMEMBERTOP() and DRILLDOWNMEMBERBOTTOM() Functions
MDX Essentials : Set Functions: The DRILLDOWNMEMBER() Function
MDX Essentials: Drilling Through with MDX: The DRILLTHROUGH Statement
MDX Essentials: String Functions: The .UniqueName Function
MDX Essentials: String Functions: The .Name Function
MDX Essentials: String / Numeric Functions: The CoalesceEmpty() Function
MDX Essentials: Basic Set Functions: The TopCount() Function, Part II
MDX Essentials: Basic Set Functions: The TopCount() Function, Part I
MDX Essentials: Enhancing CROSSJOIN() with Calculated Members
MDX Essentials: Set and String Functions: The GENERATE() Function
MDX Essentials: The CROSSJOIN() Function: Breaking Bottlenecks
MDX Essentials: String / Numeric Functions: More on the IIF() Function
MDX Essentials: String / Numeric Functions: Introducing the IIF() Function
MDX Essentials: Logical Functions: The IsEmpty() Function
MDX Essentials: Basic Set Functions: The EXTRACT() Function
MDX Essentials: Numeric Functions: Introduction to the AVG() Function
MDX Essentials: Basic Member Functions: The .Item() Function
MDX Essentials: Basic Set Functions: Subset Functions: The Subset() Function
MDX Essentials: Basic Set Functions: Subset Functions: The Tail() Function
MDX Essentials: Basic Set Functions: Subset Functions: The Head() Function
MDX Essentials: Basic Set Functions: The CrossJoin() Function
MDX Essentials: Basic Numeric Functions: The Count() Function
MDX Essentials: Basic Set Functions: The Filter() Function
MDX Essentials: Basic Set Functions: The EXCEPT() Function
MDX Essentials: Basic Set Functions: The Intersect() Function
MDX Essentials: Basic Set Functions: The Union() Function
MDX Essentials: Basic Set Functions: The Order() Function
MDX Essentials - MDX Time Series Functions, Part III: The LastPeriods() and ParallelPeriod() Functions
MDX Time Series Functions, Part II: The OpeningPeriod () and ClosingPeriod() Functions
MDX Essentials - MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions
MDX Essentials: MDX Member Functions: "Relative" Member Functions
MDX Member Functions: The Cousin () Function
MDX Essentials: Member Functions: More "Family" Functions
MDX Member Functions: The "Family" Functions
MDX Essentials: MDX Members: Introducing Members and Member
MDX Essentials : MDX Operators: The Basics
MDX Essentials: Structure of the MDX Data Model
MDX at First Glance: Introduction to SQL Server MDX Essentials








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers