MDX Essentials - MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions
July 8, 2003
About the Series ...
This is the ninth article of the series, MDX Essentials. The primary focus of this series is a hands-on introduction to the fundamentals of the Multidimensional Expressions (MDX) language. Each tutorial progressively adds features designed to meet specific real-world needs.
For more information about the series in general, as well as the software and systems requirements needed for getting the most out of the lessons included, please see the first article, MDX at First Glance: Introduction to MDX Essentials.
Note: Service Pack 3 updates are assumed for MSSQL Server 2000, MSSQL Server 2000 Analysis Services, and the related Books Online and Samples.
What We Accomplished in our Last Article
In the eighth article of the series, MDX Member Functions: "Relative" Member Functions, we performed an overview of additional "relative" member functions, expanding upon our earlier exposure to the powerful .Members function, and extending our exploration to the .CurrentMember, .PrevMember and .NextMember functions. I introduced calculated members briefly, primarily as a vehicle for demonstrating the use of the "relative" member functions. I also stated that we will take up calculated members repeatedly, and in far more detail, as the series progresses. The opportunity for exposure to them in our last article, and our recurring use of them going forward to achieve various objectives, will serve to make their characteristics and uses familiar as we progress in the series.
In this lesson, we will introduce the time series functions group. As we discussed in our last lesson, many business requirements revolve around the performance of analysis within the context of time. We saw simple approaches to meeting examples of these requirements by using the CurrentMember, .PrevMember and .NextMember functions, mainly because the time dimension provides an intuitive platform for the demonstration of many functions such as these.
Because of pervasive business needs to analyze data within the context of time, MDX provides a specialized group of time series functions to meet these needs. In this lesson, we will overview the PeriodsToDate() function, then we will discuss the specialized "shortcut" functions that are based upon it, including the YTD(), QTD(), MTD(), and WTD(). In subsequent lessons, we will explore other time series functions and expressions, together with other capabilities of MDX to help us to meet typical business needs.
In performing virtually any type of data analysis with a cube, we become acquainted early on with the need to do so with reference to time. We might receive a request to compare revenue or expense across months, quarters, or years, for example. An information consumer might need to analyze growth over periods in time, as another illustration. And common to any of us who have worked within accounting and finance circles is the requirement to present year-to-date totals, averages or other accumulations.
The time series functions are specifically designed to support time-based analysis. They are largely applied to dimensions of the "time" type, but can be applied to other dimensions as well. We can use the time series functions to produce elaborate calculations and aggregations, some of which we will introduce as the series progresses. Although, as an implementer, I have found different client environments to require differing numbers of levels within the time hierarchy (most accounting and financial scenarios have required that we present time down to the month level, but others have required the capability to report to the hour, minute, and even second levels), the time dimension within all of these environments has held one common attribute: the descendants of any given member in a time level are the same as the descendants of its peer levels. As an example, the descendants of the Year member 1997, in a typical scenario, are composed of Quarters 1 through 4, and Months January through December, while the descendants of peer Year member 1998 are identical.
The similarity in structure between members in a time dimension makes comparisons simple and efficient. The time series functions allow us to perform comparisons and other operations upon peer members that exist throughout the hierarchy (a simple example would be [Time]..Q3 and [Time]..Q3), sequential members within a given level (such as the months indicated by [Time]..[Q3].7 and [Time]..[Q3].8), and other relationships based upon hierarchical similarities. Illustration 1 depicts some of the possibilities.
In this lesson we will introduce the ubiquitous PeriodsToDate() function, addressing various common considerations of time series functions as a part of our exploration. We will also reference other specialized time series functions that are based upon the PeriodsToDate() function. Our lesson will include an introduction to the PeriodsToDate() and related specialized functions, with: