MDX Essentials – MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions

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.

Introduction

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].[1997].Q3 and [Time].[1998].Q3), sequential members within a given level (such as the months indicated by [Time].[1998].[Q3].7 and [Time].[1998].[Q3].8), and other relationships based upon hierarchical similarities. Illustration 1 depicts some of the possibilities.


Illustration 1: Time Hierarchy as Found in the HR Sample Cube (Partially Expanded)

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:

  • an examination of the syntax surrounding the use of each;
  • an illustrative example of the use of each in a practice exercise;
  • a brief discussion of the MDX results we obtain in each practice example;
  • a review of the use of calculated members, primarily as a means of exploring the time series functions of this lesson;
  • an introduction to the Sum function, and its use within a calculated member.
William Pearson
William Pearson
Bill has been working with computers since before becoming a "big eight" CPA, after which he carried his growing information systems knowledge into management accounting, internal auditing, and various capacities of controllership. Bill entered the world of databases and financial systems when he became a consultant for CODA-Financials, a U.K. - based software company that hired only CPA's as application consultants to implement and maintain its integrated financial database - one of the most conceptually powerful, even in his current assessment, to have emerged. At CODA Bill deployed financial databases and business intelligence systems for many global clients. Working with SQL Server, Oracle, Sybase and Informix, and focusing on MSSQL Server, Bill created Island Technologies Inc. in 1997, and has developed a large and diverse customer base over the years since. Bill's background as a CPA, Internal Auditor and Management Accountant enable him to provide value to clients as a liaison between Accounting / Finance and Information Services. Moreover, as a Certified Information Technology Professional (CITP) - a Certified Public Accountant recognized for his or her unique ability to provide business insight by leveraging knowledge of information relationships and supporting technologies - Bill offers his clients the CPA's perspective and ability to understand the complicated business implications and risks associated with technology. From this perspective, he helps them to effectively manage information while ensuring the data's reliability, security, accessibility and relevance. Bill has implemented enterprise business intelligence systems over the years for many Fortune 500 companies, focusing his practice (since the advent of MSSQL Server 2000) upon the integrated Microsoft business intelligence solution. He leverages his years of experience with other enterprise OLAP and reporting applications (Cognos, Business Objects, Crystal, and others) in regular conversions of these once-dominant applications to the Microsoft BI stack. Bill believes it is easier to teach technical skills to people with non-technical training than vice-versa, and he constantly seeks ways to graft new technology into the Accounting and Finance arenas. Bill was awarded Microsoft SQL Server MVP in 2009. Hobbies include advanced literature studies and occasional lectures, with recent concentration upon the works of William Faulkner, Henry James, Marcel Proust, James Joyce, Honoré de Balzac, and Charles Dickens. Other long-time interests have included the exploration of generative music sourced from database architecture.

Latest Articles