MDX in Analysis Services: Mastering Time: Introduction to Moving Averages
August 23, 2004
About the Series ...
This article is a member of the series MDX in Analysis Services. The series is designed to provide hands-on application of the fundamentals of MDX from the perspective of MS SQL Server 2000 Analysis Services; our primary focus is the manipulation of multidimensional data sources, using MDX expressions, in a variety of scenarios designed to meet real-world business intelligence needs.
For more information on the series, as well as the hardware / software requirements to prepare for the tutorials we will undertake, please see the first lesson of this series: MDX Concepts and Navigation.
Note: At the time of writing, Service Pack 3 / 3a updates are assumed for MSSQL Server 2000, MSSQL Server 2000 Analysis Services, and the related Books Online and Samples. Images are from a Windows 2003 Server environment, upon which I have also implemented MS Office 2003, but the steps performed in the articles, together with the views that result, will be quite similar within any environment that supports MSSQL Server 2000 and MSSQL Server 2000 Analysis Services ("Analysis Services" or "MSAS"). The same is generally true, except where differences are specifically noted, when MS Office 2000 and above are used in the environment, with respect to any MS Office components presented in a given article.
In this article, we resume the focus of a group of articles that began with Mastering Time: Change across Periods. In that article, as well as its immediate successor, Mastering Time: Period - to - Date Aggregations, we concentrated upon the Time dimension from the perspective of our MDX queries. Our intent, in these and occasional subsequent articles, is to explore ways to effectively report change over time, as well as to accumulate those changes to present snapshots, trends and other time-based metrics in a precise manner to meet typical business requirements. As most of us realize, time is the most pervasive dimension. A cube that has no time dimension is rare, indeed. Consequently, this group of articles holds information that is of interest to virtually anyone involved with MSAS cube design, development and use.
In this article, we will examine "rolling average" aggregations, a common business requirement. "Rolling," or "moving," averages, involve a measure, the average under consideration, that is aggregated over a progressively moving window of time periods. (While the window typically involves time, the functions that define the "window" involved here can certainly involve members of other dimensional levels).
Rolling averages are popular in the business community because they have the effect of smoothing the values of a quantity that fluctuates over time; these moving averages can be especially useful in cases where the values to which they are applied are subject to seasonal variations and other volatility factors. They aid us in "normalizing," or "flattening," the presentation of the metric for evaluation purposes. An example might be the S & P 500 Annual Yield 12-Month Rolling average, from a specific point in the past to recent times, a representation of which is depicted in Illustration 1.
As we have stated, the value of the moving average, whether presented in chart, tabular or other reports, often lies in its capacity to free us from some of the distraction of fluctuations that are meaningless, or at least not completely relevant, when it comes to trying to see long-term patterns in the analysis of a quantity / measure. Because they smooth a data series and make it easier to spot trends (something that is especially helpful in volatile markets, and in many other environments, as well), moving averages are one of the most popular and easy to use tools available to the technical analyst. Moving averages also form the building blocks for many other technical indicators and overlays.
In addition to being applied in the realm of stock prices, rolling averages are used with many other metrics that change frequently. We might, for instance, create a report to display weekly sales revenue over a three-year window. We could, in this example, plot the figures for our organization's sales revenue for each of the weeks, along with another row (or line, in the case of a chart) that displays a cumulative or a multi-week rolling average. A rolling average is generated simply by calculating the average of the current value, together with the specified number of previous values. The individual values are, of course, typically identified by a time period.
MDX affords us several approaches to generating rolling aggregates. We will explore one of these in this article, and another in the next article of this series. In both articles, we will overview the means of managing a rolling average requirement, using MDX within MSAS to accomplish our ends. We will then undertake a multi-step practice example that activates the underlying concepts, discussing our objectives, as well as the results we obtain, with each step. We will: