In this article, we will
focus on period-related comparisons. By "period," I mean
general levels of the time hierarchy, and not strictly months (some accounting
systems refer to months as "periods"). Periods can be days,
weeks, months, quarters, years, and others that occur between and external to
these.
In addition, we will pursue
a solution that handles a requirement to compare periods, but does so in such a
way that the comparison will occur at all relevant levels. We will do this
within the frame of an exercise where we build the MDX from scratch to meet a
hypothetical business requirement, so that we can assimilate the concepts in a
logical fashion, and see the working components in meaningful increments,
rather than examining an omnibus query that requires the "distraction of
dissection" that many of us have come to despise in today's pop technology
media.
Let's take a look at a
scenario that illustrates a need for a period-to-period comparison,
using a hypothetical business need to add practical value. Let's say that a
group of information consumers within the FoodMart organization have
approached us with a need that they wish to meet using data that is housed
within the Warehouse cube. The consumers want to be able to report upon
the change in Warehouse Sales from month to month, but also want the
ability to see the same delta at the quarter, semi-annual and annual levels of
the Time hierarchy for year 1997.
We will approach this in
steps, beginning with the following, and using our old friend, the Sample
Application, as a platform from which to perform our practice exercises.
1.
Start the MDX
Sample Application.
We are
initially greeted by the Connect dialog, shown in Illustration 1.
Illustration 1:
The Connect Dialog for the MDX Sample Application
The
illustration above depicts the name of my server, MOTHER1, and properly
indicates that we will be connecting via the MSOLAP provider (the
default).
2.
Click OK.
The MDX
Sample Application window appears.
3.
Click File
--> New.
A
blank Query pane appears.
4.
Ensure that FoodMart
2000 is selected as the database name in the DB box of the toolbar.
5.
Select the Warehouse
cube in the Cube drop-down list box.
The MDX
Sample Application window should resemble that depicted in Illustration 2,
complete with the information from the Warehouse cube displaying in the Metadata
tree (left section of the Metadata pane).
Illustration 2: The MDX Sample Application Window
(Compressed View)
We
will begin creating our query with a focus on building the Time hierarchy
we need into the row axis, with the single Warehouse Sales measure, initially
returning the "direct pulls" that require no calculated members. We
will then add the additional Time aggregations we need, in the next step.
Finally, in the last enhancements to the core query, we will add a calculated
member, which we will call "Delta-to-Last," meaning "change
over the last period." Delta-to-Last will reflect the appropriate
change value at any level of the hierarchy.
6.
Create the following new query:
-- MXAS15-1: Simple Time Hierarchy on Row Axis
SELECT
{ [Measures].[Warehouse Sales] } ON COLUMNS,
{ [Time].[Year].[1997].[Q1].Children,
[Time].[Year].[1997].[Q1],
[Time].[Year].[1997].[Q2].Children,
[Time].[Year].[1997].[Q2],
[Time].[Year].[1997].[Q3].Children,
[Time].[Year].[1997].[Q3],
[Time].[Year].[1997].[Q4].Children,
[Time].[Year].[1997].[Q4],
[Time].[Year].[1997]} ON ROWS
FROM
[Warehouse]