dcsimg

MDX Essentials - MDX Time Series Functions, Part III: The LastPeriods() and ParallelPeriod() Functions - Page 3

September 8, 2003

The ParallelPeriod() Function

The ParallelPeriod() function, according to the Analysis Services Books Online, "returns a member from a prior period in the same relative position as a specified member." This function would serve, as an illustration, to make it easy for us to navigate to "our current point in the year, last year," be the current point a month, quarter, or other period supported by our cube structure.

Similar to the case of the Cousin() function (see the seventh article in this series, Member Functions: The Cousin () Function), the ParallelPeriod() function operates upon the order and position of members within levels; ParallelPeriod() returns the child member with the same relative position under a given parent member as the specified child member under its own parent. The ParallelPeriod() function is more specifically adapted to time dimensions than Cousin(). It takes the ancestor of the specified member (in the typical case, a period), at a specified level, then looks at the specified sibling of the ancestor (who lags by a specified numeric expression) and returns the parallel period of the specified member from the descendants of that sibling.

When a level is not specified, the default member is Time.CurrentMember. When a level is specified, the default member is Dimension.CurrentMember, where Dimension is the dimension within which the specified level is a member. The default level is the parent of the specified member. The "lag distance" specified in the numeric expression defaults to "1," when it is not specified.

Discussion

The ParallelPeriod() function allows us to meet a business need that is common to virtually all industries. It allows us to return, for a given period, a value for its parallel in another time frame. ParallelPeriod() allows us to compare, for example, the sales over a given month with the sales that took place over the same month in the prior year, or a for a quarter this year over the same quarter last year. This might be particularly useful in a business whose revenues are highly seasonal (as in the case of a retail organization for whom Q4 - a large portion of which is Christmas shopping season - might make more sense to compare to Q4 of the prior year, rather than to Q3 of this year, when sales might have been (unsurprisingly) less.

As is the case with most of the time series functions, other, less direct approaches exist to meet business requirements of this nature. But ParallelPeriod() provides an easy, time-focused approach to this common need, as we will see in the sections that follow.

Syntax

Syntactically, the level, the sibling lag expression, and the specified member is placed within the parentheses to the right of ParallelPeriod(), as shown in the following illustration:

ParallelPeriod([<<Level>>[, <<Numeric Expression>>[, <<Member>>]]])

ParallelPeriod() takes the ancestor of <<Member>> at <<Level>> in the first argument, then returns the period parallel to <<Member>> under the ancestor's sibling that lags by <<Numeric Expression>>. The following simple example expression:

 ParallelPeriod ([Quarter], 2,[1998].[Q3].[9])

navigates to the sibling of the quarter-level ancestor of Quarter 3 (Q3 in the FoodMart sample cubes) in 1998, moves two quarters back (to Quarter 1), and then returns the cousin of September, (Month "9" in the FoodMart cubes) 1998. The month that is returned is therefore March (Month "3" in the FoodMart cubes).

Practice

Let's confirm our understanding of the function under consideration by using the ParallelPeriod() function in a way that we can get a feel for its operation.

We will create a simple query, which will again focus on Warehouse Cost.

1.  Type the following query into the Query pane:

-- MDX11-2:  Tutorial Query No. 2
SELECT
  
{[Measures].[Warehouse Cost]} ON COLUMNS,    
     { ParallelPeriod ([Quarter], 2,[1998].[Q3].[9])}ON ROWS
FROM Warehouse

Analysis Services fills the Results pane, presenting the dataset depicted in Illustration 3.


Illustration 3: Result Dataset - ParallelPeriod() Function

We see the total Warehouse Cost returned for Month 3 of Quarter 1 of 1998. As we discovered above, Quarter 1 is two quarters back from Quarter 3, which is the value of the numeric expression / index in the ParallelPeriod() function that we have used. Once we navigate to Quarter 1, the parallel month to Month 9 in Quarter 3 (the "last of the three months" in the quarter) is Month 3 (also the "last of the three months of the quarter").

We can prove the accuracy in the use of the ParallelPeriods() function by first reasoning that the "cousin" month for September (the third month in its quarter) in any given year is as follows for each of the other quarters of the year:

Quarter 1

March

Quarter 2

June

Quarter 4

December

Table 1: "Cousins" - The Third Month in Each Quarter

We realize that we wish to navigate to two quarters back in the timeline, so we know that we wish to focus on Quarter 1. Reasoning tells us that March, 1998, is therefore our targeted time dimension member.

Next, we can simply query the cube for the Warehouse Cost value for March 1998, by taking the following steps:

2.  Type the following query into the Query pane:

-- MDX11-2 Proof: Tutorial Query No. 2 Proof
SELECT    
  
{[Measures].[Warehouse Cost]} ON COLUMNS,    
    { [Time].[1998].[Q1].[3]} ON ROWS
FROM Warehouse

3.  Click the Run button on the toolbar atop the Sample Application, to execute the query.

Analysis Services does its work, resulting in the result dataset shown in Illustration 4.


Illustration 4: The Proof Query Result Dataset

The proof query delivers the results that we expected, based upon an alternative approach to the ParallelPeriods() function that we ran initially: The same results are generated from a more direct request for the value at the "parallel" month that the function should have, and apparently did, insert for us in the previous query.

In conclusion, we can easily see the utility of the LastPeriods() and ParallelPeriod () functions in providing us a relative route to data that is typically most useful within the context of time - utility that we can fine-tune with parameters that we can specify within arguments provided to the function.

Summary...

In this lesson, we concluded our examination of several useful members of the time series functions group, with two additional time-related functions, LastPeriods() and ParallelPeriod(). After discussing further the general business need to analyze data over time, we first overviewed the LastPeriods() and ParallelPeriod() functions. For each function, we then illustrated the syntax that is appropriate for its effective use. Finally, we tested our understanding of how to leverage the function by undertaking a relevant practice exercise, discussing the results we obtained and performing additional proof exercises to confirm their accuracy.

» 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