2074A_11
2074A_11
Implementing
Calculations Using MDX
Contents
Overview 1
Understanding Calculated Members 2
Building Calculated Members 6
Lab A: Creating Average Price 9
Lab B: Creating Sales Variance
Calculations 14
Creating Non-Measure Calculated
Members 17
Lab C: Creating a Non-Measure
Dimension 20
Using Functions within Calculated
Members 22
Lab D: Creating Calculated Members with
Functions 24
Understanding Other Calculation
Methods 29
Introducing Solve Order 32
Review 34
Information in this document, including URL and other Internet Web site references, is subject to
change without notice. Unless otherwise noted, the example companies, organizations, products,
people and events depicted herein are fictitious and no association with any real company,
organization, product, person or event is intended or should be inferred. Complying with all
applicable copyright laws is the responsibility of the user. Without limiting the rights under
copyright, no part of this document may be reproduced, stored in or introduced into a retrieval
system, or transmitted in any form or by any means (electronic, mechanical, photocopying,
recording, or otherwise), or for any purpose, without the express written permission of Microsoft
Corporation.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
Microsoft, MS-DOS, Windows, Windows NT, ActiveX, BackOffice, FoxPro, JScript, MS-DOS,
PivotChart, PivotTable, PowerPoint, Visual Basic, Visual C++, and Visual Studio are either
registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.
© 2001 OLAP Train, LLC. All Rights Reserved. Developed by OLAP Train LLC, for Microsoft
Corporation and distributed under license.
Other product and company names mentioned herein may be the trademarks of their respective
owners.
Module 11: Implementing Calculations Using MDX iii
Instructor Notes
Presentation: In addition to performance and the intuitive nature of the multidimensional
45 Minutes model, the ability to perform complex calculations is one of the key benefits of
online analytical processing (OLAP). In some respects, an OLAP database is
Lab: something in between a relational database and a spreadsheet. This is why
45 Minutes OLAP is a tool used extensively by analysts. Calculated members in Microsoft®
SQL Server™ 2000 Analysis Services play a vital role in cube functionality and
analysis. In this module, students will learn the rudiments of working with
calculated members and multidimensional expressions (MDX).
After completing this module, students will be able to:
Describe how calculated members work.
Explain the mechanics of the Calculated Member Builder and create
calculated members.
Create calculated members in non-Measure dimensions.
Understand the use of functions in calculated members.
Understand other calculation methods in Analysis Services.
Understand the importance of Solve Order to generate accurate results.
iv Module 11: Implementing Calculations Using MDX
Required Materials
To teach this module, you need Microsoft PowerPoint® file 2074A_11.ppt
Preparation Tasks
To prepare for this module, you should:
Read all the student materials.
Read the instructor notes and margin notes.
Complete all the demonstrations.
Practice the lecture presentation and demonstration.
Complete the labs.
Review the Trainer Preparation presentation for this module on the Trainer
Materials compact disc.
Review any relevant white papers that are located on the Trainer Materials
compact disc.
Module 11: Implementing Calculations Using MDX v
4. What is the value for the All Product, All Time, North American Bad
Price?
$13,061.94
____________________________________________________________
vi Module 11: Implementing Calculations Using MDX
5. The value is incorrect. What should the value be equal to for the All
Product, All Time, North American Bad Price?
$2.17
____________________________________________________________
3. Click the division sign button (/) below the Insert button.
Notice the Value expression box contains the following expression:
[Measures].[Sales Dollars]/
5. Click Check to verify that the expression is correct, and then click OK.
6. Remove the right bracket from Sales Units. Notice the red left bracket,
indicating that the measure name is not correct and requires a right bracket.
7. Add the right bracket to the Sales Units measure to finish the calculation
expression.
viii Module 11: Implementing Calculations Using MDX
6. The value is correct, because the price calculation occurs after the
aggregation of the cube instead of before the aggregation.
7. Save the Sales cube.
Module 11: Implementing Calculations Using MDX ix
The ampersand (&) before the member indicates the use of the key for the
member, and not the name.
3. Add the plus sign (+) to the Value expression box, adding it to the end of
Dairy.
4. Insert the Meat Product member.
The expression should be the following:
[Product].[Category].&[Dairy]+[Product].[Category].&[Meat]
____________________________________________________________
3. Notice the Product dimension and Dairy + Meat below the Meat member.
Dairy + Meat intersects with all measures in the Sales cube. It also
intersects all other members in all other dimensions.
4. Verify that the calculation is correct for Dairy + Meat.
5. Save the Sales cube.
Module 11: Implementing Calculations Using MDX xi
The «Set» parameter indicates that the Avg function requires a Set as its
only parameter.
In the context of this exercise, a Set defines multiple members from the
same dimension.
Note Sets are important fundamental MDX constructs, and are defined
thoroughly in course 2093A, Implementing Business Logic with MDX in
Microsoft SQL Server 2000.
Other Activities
Difficult Questions
Below are difficult questions that students may ask you during the delivery of
this module and answers to the questions. These materials delve into subjects
that are within the scope of the module but are not specifically addressed in the
content of the student notes.
1. Where do calculated members process?
Calculated members process on both the server and client computers.
Analysis Services is designed for client-server environments, with
clients sharing a significant amount of the work in processing
calculations.
2. Can you force Analysis Services to process all calculations on the server
computer?
Yes. If you do not want the client computers processing calculations,
you can update the Analysis Server connection string in custom client
applications. An execute location property exists that can be set to force
calculations to process entirely on the server, therefore enabling a more
thin-client deployment.
3. Are there other MDX and calculated member resources?
Yes. The course 2093A, Implementing Business Logic with MDX in
Microsoft SQL Server 2000 is a very good resource for developing
calculations in Analysis Services cubes by using MDX.
4. Can calculated members affect query performance?
Yes. Calculated members with inefficient designs can severely affect
query times. It is important to understand the proper way in which to
design complex calculated members.
xiv Module 11: Implementing Calculations Using MDX
Module Strategy
Use the following strategy to present this module:
Understanding Calculated Members
Teach students that a key mechanism for performing calculations with
Analysis Server is the use of calculated members. Explain that the
expressions used to define calculated members use a language called MDX,
which stands for multidimensional expressions.
Building Calculated Members
Introduce the Calculated Member Builder and describe its components
that assist in creating calculated members. Introduce the interface for
building calculated members in Analysis Manager—the Calculated
Member Builder, which is a dialog box used for creating calculated
members in regular and virtual cubes.
Creating Non-Measure Calculated Members
Introduce the concept of creating calculated members in non-Measure
dimensions. Tell students that a calculated member can belong to any
dimension.
Using Functions within Calculated Members
Discuss functions and their use in calculated members. Show that the MDX
language has many functions that are available to create complex calculated
members.
Understanding Other Calculation Methods
Explain to students that there are calculation methods other than the creation
of calculated members. Analysis Services provides a variety of methods for
defining calculations by using MDX.
Introducing Solve Order
Discuss the importance of setting Solve Order for calculated members. The
Solve Order feature in Analysis Services allows you to specify the order in
which calculations execute.
Module 11: Implementing Calculations Using MDX 1
Overview
Topic Objective
To provide an overview of
the module topics and
objectives. Understanding Calculated Members
Lead-in Building Calculated Members
In this module, you will learn
about calculated members Creating Non-Measure Calculated Members
and how to use them in
OLAP cubes to enhance Using Functions within Calculated Members
analysis.
Understanding Other Calculation Methods
Introducing Solve Order
Note The Parent member does not determine the aggregation of the
calculated member, because calculated members do not aggregate. The
Parent member merely dictates the placement of the calculated member in
the dimension hierarchy.
Member name. Defines the name of the calculated member. For example,
the calculated member in the preceding illustration is Average Selling
Price.
Check. Validates the expression in the Value expression box.
Value expression. Contains the expression used to define the calculated
member. You either type the expression into the Value expression box, or
drag dimension and function values to the box.
Data. Defines the cube metadata containing dimension, hierarchy, level, and
member information. Add metadata to an expression by double-clicking the
object, clicking Insert, or dragging the object to the Value expression box.
Functions. Contains the MDX functions available for creating calculated
members. Similar to the Data box, it allows you to double-click, click
Insert, or use a drag and drop operation to add functions to your
expressions. The MDX function library is included in the Function box,
plus any external function libraries that you registered in the Calculated
Member Builder.
Insert. Inserts objects or functions from the Data or Functions box into the
Value expression box.
Numbers and Operators. Gives you the ability to add numeric constants or
arithmetic operators to expressions without having to use the keyboard.
Register. Allows you to register external function libraries.
8 Module 11: Implementing Calculations Using MDX
Prerequisites
Before working on this lab, you must have:
Experience working with the Cube Editor.
An understanding of dimensions, cubes, and measures.
Exercise 1
Creating Average Price
In this exercise, you will open the Calculated Member Builder and navigate
the Data box to view dimensions, levels, and members in the Sales cube. You
then will create a new calculated member, Average Price, and will browse the
results in the Cube Editor.
4. What is the value for the All Product, All Time, North American Bad
Price?
$13,061.94
____________________________________________________________
Module 11: Implementing Calculations Using MDX 11
5. The value is incorrect. What should the value be equal to for the All
Product, All Time, North American Bad Price?
$2.17
____________________________________________________________
3. Click the division sign button (/) below the Insert button.
Notice the Value expression box contains the following expression:
[Measures].[Sales Dollars]/
5. Click Check to verify that the expression is correct and then click OK.
6. Remove the right bracket from Sales Units. Notice the red left bracket,
indicating that the measure name is not correct and requires a right bracket.
7. Add the right bracket to the Sales Units measure to finish the calculation
expression.
Module 11: Implementing Calculations Using MDX 13
6. The value is correct, because the price calculation occurs after the
aggregation of the cube instead of before the aggregation.
7. Save the Sales cube.
14 Module 11: Implementing Calculations Using MDX
Prerequisites
To complete this lab, you must first complete lab A, Creating Average Price,
found earlier in this module.
Exercise 1
Creating Sales Variance
In this exercise, you will create a new calculated member, Sales Variance, by
using the Calculated Member Builder.
Exercise 2
Creating Sales Variance %
In this exercise, you will create a new calculated member, Sales Variance %,
by using the Calculated Member Builder. You will learn how to reference a
calculated member in the expression of another calculated member.
Common Applications
A common application of calculated members outside the Measures dimension
is a calculated member that compares the performance of one member to
another. You can also create non-Measure calculated members to create rollups
outside the natural dimension hierarchy.
The following list contains examples of non-Measure calculated members:
A time dimension contains members 2000 and 2001. You can create a
calculated member in the time dimension that calculates the difference, or
variance, between the two years.
A sales representative dimension can contain a calculated member that
calculates the average performance for all sales representatives.
A product dimension can contain a calculated member that sums products
outside their regular hierarchy aggregations.
Aggregation Behavior
Calculated members do not roll up in the parent dimension. Therefore,
calculated member values do not affect or add to cube aggregations.
Prerequisites
Before working on this lab, you must have:
Experience working with the Cube Editor.
An understanding of dimensions, cubes, and measures.
Experience working with the Calculated Member Builder.
Completed lab A, Creating Average Price, found earlier in this module.
Completed lab B, Creating Sales Variance Calculations, found earlier in this
module.
Exercise 1
Creating Time Variance
In this exercise, you will create a non-Measure dimension calculated member.
The new calculated member, Time Variance, will calculate the difference
between years 2000 and 2001.
Prerequisites
Before working on this lab, you must have:
Experience working with the Cube Editor.
An understanding of dimensions, cubes, and measures.
Experience working with the Calculated Member Builder.
Completed lab A, Creating Average Price.
Completed lab B, Creating Sales Variance Calculations.
Completed lab C, Creating a Non-Measure Dimension.
Exercise 1
Creating Average Product Category
In this exercise, you will create a non-Measure dimension calculated member
that uses the Avg function. The new calculated member, Average Product
Category, calculates the average of all Category level members.
The «Set» parameter indicates that the Avg function requires a Set as its
only parameter.
In the context of this exercise, a Set defines multiple members from the
same dimension.
Note Sets are important fundamental MDX constructs, and are defined
thoroughly in course 2093A, Implementing Business Logic with MDX in
Microsoft SQL Server 2000.
Exercise 2
Creating Total Quarter
In this exercise, you will create a calculated member in the Time.Calendar
dimension to test the value for the aggregated All Time member. You will use
the Sum function to add all members in the Quarter level.
Because Total Quarter calculates all measures, you do not need to specify
a numeric expression.
2. The Value expression box contains the following template:
Sum(«Set»)
3. In the Functions list, expand the Set folder and find the Members – Level
function.
4. Click the «Set» parameter in the Value expression box.
5. Drag Members – Level to the «Set» parameter.
28 Module 11: Implementing Calculations Using MDX
Give students brief Custom rollup formulas override the Aggregate Function properties
examples of when they use defined for the cube measures across a dimension level.
each type of calculation.
You use custom rollup formulas when you need members to aggregate
differently from the standard Aggregate Function properties defined for
measures.
For example, if you do not want Quarter member values to sum to the
Year level, you can create a custom rollup formula for the Year level,
defining its calculation as the following expression:
Time.CurrentMember.LastChild
Calculated Cells
Calculated cells are similar to calculated members, except that they supply data
for an existing range of cells, or even a single cell, instead of creating a single
member applied across all other dimensions. The following list describes
calculated cells:
Calculated cells are calculations developed by using MDX that supply
values for cells in a specified range of existing cells.
You create calculated cells when you require a calculation applied to a finite
number of cube cells and not to all cells across a single dimension.
For example, to apply a Budget Expense allocation calculation to only
those stores in Illinois that produce Sales in excess of $500,000, you can
create a calculated cell that focuses on those specific cells. You therefore
avoid creating a separate calculated member that calculates across all stores
for Budget and Actual values.
The original cell values are not lost when you create calculated cells.
Therefore, you do not affect underlying data when adding calculated cells to
a cube.
Calculated cell results are not stored, they evaluate at query time.
You create calculated cells by first defining a calculation subcube, or a
range of cells in a cube.
You must also define a calculation condition and a calculation formula.
• The calculation condition determines which cells perform the calculation
formula.
• The calculation formula is the MDX used to calculate the cells specified
by the calculation condition.
You create calculated cells by using the Calculated Cells Wizard.
If a cube cell contains a custom member formula and a calculated cell
formula, the calculated cell formula overrides the custom member formula.
32 Module 11: Implementing Calculations Using MDX
This is the expected result. However, if the Dairy + Meat member calculates
after the Average Sales member, the result is equal to $5.33. Consider the
calculation order:
1. Sales / Units for Dairy = $1.33
2. Sales / Units for Meat = $4.00
3. (Sales / Units for Dairy) + (Sales / Units for Meat) = $1.33 + $4.00 =
$5.33
The two results are very different. You can define the order of the two
calculations by updating the Solve Order property. Managing Solve Order is
critical in a multidimensional environment when calculations intersect. It is
important that you understand Solve Order and update the property in specific
situations.
Set the Solve Order property in calculated members that exist in separate
dimensions, and therefore intersect at cells. If you do not set the Solve Order
property, Analysis Services sets the calculation order based on order
declarations, which could give you misleading results. Different calculation
types—for example calculated cells, custom member formulas, and calculated
members—use different solve orders. You can refer to SQL Server Books
Online for a listing of the default solve orders for each type of calculation.
Note Solve Order and Pass Order (the order of calculation stages) are very
complex concepts. For more information on both concepts, refer to SQL Server
Books Online or course 2093A, Implementing Business Logic with MDX in
Microsoft SQL Server 2000.
34 Module 11: Implementing Calculations Using MDX
Review
Topic Objective
To reinforce module
objectives by reviewing key
points. Understanding Calculated Members
Lead-in Building Calculated Members
The review questions cover
some of the key concepts Creating Non-Measure Calculated Members
taught in the module.
Using Functions within Calculated Members
Understanding Other Calculation Methods
Introducing Solve Order
6. Where do you update the Solve Order property? Give an example of when
the solve order might be used.
You update the Solve Order property on the Advanced tab of the
Properties pane in the Cube Editor.
Use Solve Order when calculated members intersect, or when multiple
calculations depend on each other.
THIS PAGE INTENTIONALLY LEFT BLANK