Home > Articles > Data > SQL Server

Like this article? We recommend

Measuring Change over Time with MDX Expressions

As a final section in our examination of several intermediate MDX concepts, we'll explore the Time dimension, a component of the vast majority of cubes that are created. Financial and other business reporting needs almost always contain a time element, the purposes of which typically include the isolation of results to a specific reporting period, such as the following:

  • Providing a basis for comparison of the current period results to those of the immediately preceding period (year, quarter, month, and so on)

  • Providing a means for comparing parallel periods (the current month, but in the prior year, for example) to build in seasonality factors for the business

MDX provides for the analysis of values over time with a large and robust group of functions that are well suited to the purpose. In this section, we'll explore the ways we can use these functions to achieve time-based analysis objectives.

Let's first look at a common scenario: the calculation of change over a period of time. As the basis of our study, we will again use the Budget cube, with a calculated member to expose the handling of this basic time consideration.

Analyzing Change in Values from a Prior Measurement Period

Near and dear to virtually any participant in business is the concept of analyzing change over the prior operating period, particularly over the prior month. MDX handles time like any other dimension—with hierarchies and members that it handles efficiently. Let's add a time consideration to our existing project, and get a feel for the ease with which MDX enables the support of the time-based analysis needs of information consumers.

First, let's provide some screen real estate for things to come by removing the calculated members from our recent efforts. Then we'll begin our exploration of the MDX time functions.

  1. Select the Avg Rev Per Unit Sold calculated member.

  2. Right-click and select Delete from the context menu.

  3. Click Yes at the confirmation dialog box to complete the deletion.

  4. In the same way, delete the Sales Units calculated member and the Expense % calculated member.

  5. Drag the Time dimension from the top pane down to replace the dimension in the row axis. The heading will appear as Year, with the levels 1997 and 1998 appearing just underneath.

  6. Expand the 1997 and Q4 levels in the Row axis.

Now we'll create a new calculated member to demonstrate the use of time functions in MDX expressions.

  1. Double-click the Time dimension heading in the row axis to collapse and zoom the Time dimension back to the Year levels.

  2. Double-click Year 1998 to expand Year 1998 to the Quarter level.

  3. In similar fashion, drill down in the 1998 Quarter level to reach the Month level of 1998.

  4. Select All Account in the filter field for the Account dimension.

  5. Choose Insert, Calculated Member to display the Calculated Member Builder.

  6. Type Prior Amount in the Member Name box.

  7. In the Functions tree, expand the Member folder (see Figure 12).

    Figure 12Figure 12 Preparing to add the expression.


  8. Double-click the PrevMember function within the Member folder.

  9. Click the <<Member>> token to select it.

  10. Double-click the CurrentMember function within the Member folder.

  11. Click the newly appearing <<Dimension>> token to select it.

  12. Double-click the Time dimension within the Data tree.

    Figure 13 shows the Calculated Member Builder at this point.

    Figure 13Figure 13 The expression takes form.


    The PrevMember function works in a fashion very similar to that of Ancestor (another member function we've used several times in this series). It refers to the current member as a starting point, and returns the immediately preceding member occupying the same level in the Time hierarchy. This is especially useful within the context of year-end cutoffs and other financial and accounting time-range boundaries; the function ignores such boundaries and returns the immediately preceding member.

  13. Append the following text to the expression in the Value Expression box, and then enclose the entire expression in parentheses.

    , [Amount]

    Figure 14 shows the final expression.

    Figure 14Figure 14 The expression as it appears in the Value Expression box.

  14. Click OK to accept the expression as displayed. Figure 15 shows the results.

    Figure 15Figure 15 The results in the data viewing pane.

You can readily see that the values that appear in the Prior Amount column accurately reflect the prior period balance, as shown in the associated previous time period slot in the Amount column. For example, the Q3, Month 8 Prior Amount ($86.505.46) matches the Q3, Month 7 Amount. The same applies to the Quarter level rollups (except for periods for which the cube doesn't contain data for a prior period or other time member).

MDX handles parallel-period time considerations in much the same fundamental way: through the comprehension of hierarchical relationships that was built into its design.

Analyzing Change in Values from a Parallel Measurement Period

Another good example of real-world time-based analysis is the concept of parallel periods. In essence, the concept entails comparing a period in one year with the corresponding period in another year; for example, comparing June 1998 to June 1997.

This comparison is useful for comparing seasonal changes in business operations. For a retail establishment, for example, it might be useful to compare the sales in the fourth quarter of a given calendar year (the Christmas shopping season) with those of the fourth quarter of the previous calendar year, rather than to compare Q4 1998 results to Q3 1998 results, when sales are hardly comparable.

MDX provides parallel functions to support these sorts of analytical needs. We'll practice an example with the following steps:

  1. Drill down the Quarters level of the 1997 Year level to make the months of 1997 visible in addition to those of 1998 (for comparative purposes).

  2. Choose Insert, Calculated Member to display the Calculated Member Builder.

  3. Type Parallel Amount in the Member Name box.

  4. Type the following expression in the Value Expression box (see Figure 16):

    (ParallelPeriod(),[Amount])

    While the ParallelPeriod function can be found in the Member folder of the Functions tree (similarly to the PrevMember function used earlier), our sample expression is actually easier to type than to build from the objects in the Functions and Data trees. The () in the expression above represents an empty argument pair, used to stipulate levels "removed" from the current member, as well as other sophistications. The arguments are optional, and won't be needed for our initial practice exercise.

    Figure 16Figure 16 A simple example of a parallel period expression.

  5. Click OK. The results should appear as partially depicted in Figure 17

    Figure 17Figure 17 The partial results set in the data viewing pane.

The effect of the expression has been to match a period (month, in this case) for a given quarter level with the same relative month (first, second, or third) of the quarter immediately preceding it. This is a "parallel month" in its most basic form. Notice that the quarter amounts of the same quarter in the previous year are shown as the parallel amount.

Let's insert an argument to further leverage the flexibility of the expression.

  1. Return to the Value Expression box for the Parallel Amount calculated member.

  2. Place the following text within the parentheses for the argument discussed earlier:

    [Year]

    The completed expression should now appear as follows:

    (ParallelPeriod([Year]),[Amount])
  3. Click OK. Figure 18 shows the results.

    Figure 18Figure 18 The results with the modified ParallelPeriod function.

Each Amount value (each level) now has a matching Parallel Amount in the respective reporting period of the previous year (except where no data exists within the cube to be retrieved).

Let's conclude the lesson with the computation of a variance (often called delta or simply growth) between the current Amount and the Prior and Parallel Amounts. This is handled via a simple subtraction of one calculated member from another.

  1. Double-click the Quarter dimension heading to zoom up, freeing some real estate for our next step.

  2. Choose Insert, Calculated Member to display the Calculated Member Builder.

  3. Type Change Over Prior Period in the Member Name box.

  4. In the Value Expression box, type the following expression:

    [Amount]-[Prior Amount]
  5. Click OK to accept the expression entered.

    Compare the result set to that partially shown in Figure 19. Keep in mind the effects that are to be expected when dealing with debit/credit (+ or -) signs.

    Figure 19Figure 19 The new Change Over Prior Period column appears.

    Notice that we didn't have to set the format string for the new calculated member; it automatically assumed the format string of the two calculated members from which it was computed.

  6. Choose Insert, Calculated Member to display the Calculated Member Builder.

  7. Type Change Over Prior Year in the Member Name box.

  8. In the Value Expression box, type the following expression:

    [Amount]-[Parallel Amount]
  9. Click OK to accept the expression entered.

    Compare the result set to that partially shown in Figure 20.

    Figure 20Figure 20 The new Change Over Prior Year column appears.

  10. Save your work by selecting File, Save from the top menu.

These exercises have shown the relative ease with which you can embed the concept of time within MDX expressions to support the time-based analysis needs of information consumers, such as the quantification of change in values over time. The inherent grasp of hierarchical relationships that's integral to the design of MDX makes handling time members quite similar to handling members of any other dimension.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020