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.

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

MDX Essentials Series