0% found this document useful (0 votes)
3 views50 pages

2074A_11

Module 11 focuses on implementing calculations using MDX in Microsoft SQL Server 2000 Analysis Services. It covers the creation of calculated members, including average price and sales variance calculations, as well as the use of functions and understanding solve order for accurate results. The module includes demonstrations and labs to reinforce learning and practical application of the concepts discussed.

Uploaded by

vsergio1975
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views50 pages

2074A_11

Module 11 focuses on implementing calculations using MDX in Microsoft SQL Server 2000 Analysis Services. It covers the creation of calculated members, including average price and sales variance calculations, as well as the use of functions and understanding solve order for accurate results. The module includes demonstrations and labs to reinforce learning and practical application of the concepts discussed.

Uploaded by

vsergio1975
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Module 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.

 2001 Microsoft Corporation. All rights reserved.

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

Materials and Preparation


This section lists the required materials and preparation tasks that you need to
teach this module.

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

Demonstration: Using the Calculated Member Builder


The following demonstration procedures provide information that will not fit in
Demonstration: the margin notes or is not appropriate for student notes.
15 Minutes
You create calculated members to enhance analysis in cubes and virtual cubes.
The Calculated Member Builder dialog box provides a simple interface for
creating expressions and assists in developing calculated members.
In this demonstration, you will open the Calculated Member Builder and will
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.

 To restore a new database and define a data source


1. In Analysis Manager, right-click the server, click Restore Database, click
the Look in list, click the file C:\Moc\2074A\Labfiles\L11\Module
11.CAB, click Open, click Restore, and then click Close.
2. Double-click Module 11 to expand the database.
3. Below Module 11, double-click the Data Sources folder, right-click the
Module 11 data source, and then click Edit.
4. Click the Connection tab of the Data Link Properties dialog box, and then
verify that localhost is selected in step 1.
5. In step 2, click Use Windows NT Integrated security.
6. In step 3, click Module 11.
7. Click Test Connection and verify that the test succeeded, click OK, and
then click OK to exit the Data Link Properties dialog box.

 To review Bad Price


1. In the Module 11 database, open the Cube Editor for the Sales cube.
2. Browse the cube in the Data pane.
3. In the cube tree view, click the Bad Price measure.
Notice that Bad Price is a derived measure. What expression is defined for
Bad Price in the Source Column?
"dbo"."SalesFact"."Sales_Dollars" /
"dbo"."SalesFact"."Sales_Units"
____________________________________________________________

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
____________________________________________________________

Bad Price is a derived measure that uses an expression to calculate Sales


Dollars divided by Sales Units. Measures calculate at cube processing time
and aggregate across all dimensions in the cube, based on the Aggregate
Function associated with the measure. Bad Price incorrectly sums its value
across all dimensions.
Instead of creating a derived measure for average price, you will create a
new calculated member that calculates the average. Because calculated
members do not aggregate, you will see correct values for the price.

 To open the Calculated Member Builder


1. In the Cube Editor for the Sales cube, right-click the Calculated Members
folder, and then click New Calculated Member.
The Calculated Member Builder dialog box opens. Here you create and
modify calculated members in Analysis Manager.
2. Notice the Measures dimension in the Parent dimension list.
Having the Measures dimension defined in the Parent dimension list
indicates that the new calculated member resides in the Measures
dimension. You have the option of selecting any of the cube dimensions in
the Parent dimension list. However, do not change Measures.
3. Delete the default name and then type Average Price in the Member name
box.
4. In the Data box, click the plus sign (+) to the left of the Measures
dimension.
Notice the one item, MeasuresLevel, positioned immediately below the
Measures dimension. The fact that Measures contains only one item below
it indicates that Measures contains only one level. All measures dimensions
contain only one level, because they are flat dimensions.
5. Click MeasuresLevel. Notice the status box at the bottom of the
Calculated Member Builder.
The status box contains two lines— Level: MeasuresLevel and
[Measures].[MeasuresLevel]. The first line indicates the object type of
MeasuresLevel. In this instance, MeasuresLevel is a level object. The next
line presents the official name of the object used in calculated member
expressions. In this instance, the official name of the level is
[Measures].[MeasuresLevel].
6. Click the plus sign (+) to the left of MeasuresLevel.
Notice the seven measures below MeasuresLevel. The measures exist in the
one level of the Measures dimension.
7. Click each of the seven measures and notice the object type and official
name of each one.
Module 11: Implementing Calculations Using MDX vii

 To explore other dimensions


1. Click the plus sign (+) to the left of the State dimension.
Notice the four levels in the State dimension—(All), Country, Region, and
State.
2. Expand each of the levels in the State dimension and notice the members
below each level. Compare the State dimension to the Measures
dimension.
3. Notice that you can drill down to lower level members in each of the State
dimension levels.
4. Notice the four property templates below each member that you use to insert
various member properties into expressions.
5. Expand the Time dimension. Notice the two hierarchies in the Time
dimension—Calendar and Fiscal. Expand each of the hierarchies to the
members found at all the levels.
The Calculated Member Builder shows the hierarchy construct in
dimensions and presents hierarchies below dimensions, with the appropriate
levels and members below.

 To create Average Price


1. In the Calculated Member Builder, expand the Measures dimension to the
individual measures.
2. Double-click Sales Dollars.
Notice that [Measures].[Sales Dollars] appears in the Value expression
box. The format of the name is:
[DimensionName].[MemberName]

3. Click the division sign button (/) below the Insert button.
Notice the Value expression box contains the following expression:
[Measures].[Sales Dollars]/

4. Drag Sales Units to the Value expression box, after


[Measures].[Sales Dollars]/

The expression is now:


[Measures].[Sales Dollars]/[Measures].[Sales Units]

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

 To browse Average Price


1. In the Calculated Member Builder, click OK.
In the Data pane, you see the cube browser retrieving cube data.
2. Scroll to the right of Unique Product Count. You see the newly created
calculated member, Average Price.
When you add a new calculated member to a cube, you do not need to
reprocess the cube. The calculated member automatically produces the
correct values, assuming that the calculation expression is correct.
3. In the Calculated Members folder, click Average Price, and then click the
Advanced tab of the properties pane.
4. For the Format String property, click the Currency format.
5. Browse the cube and notice the value of the All Product, All Time, North
American Average Price. What is the value?
$2.17
____________________________________________________________

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

Demonstration: Creating a Product Rollup


The following demonstration procedures provide information that will not fit in
Demonstration: the margin notes or is not appropriate for student notes.
15 Minutes
In this demonstration, you will create a non-measure dimension calculated
member. The new calculated member, Dairy + Meat, will calculate a product
rollup, summing Dairy and Meat.

 To create a new calculated member


1. In the Cube Editor for the Sales cube, create a new calculated member.
2. In the Parent dimension list, click Product.
The calculated member will reside in the Product dimension.
3. Notice the Parent member box.
When Measures is selected in the Parent dimension list, the Parent
member box is disabled, because Measures is a flat dimension with no
parents and no children. However, the Parent member box is enabled when
non-measure dimensions are selected in the Parent dimension list.
4. To the right of the Parent member box, click Change.
5. Expand the Product dimension and notice the levels included in the Select
the parent member dialog box.
The Select the parent member dialog box contains all levels of the
dimension, except for the lowest level of the selected dimension.
6. Click the All Product member, and then click OK.

 To define the calculation


1. In the Calculated Member Builder, delete the default name and then type
Dairy + Meat in the Member name box.
2. Insert the Dairy Product member into the Value expression box.
Notice the official name of Dairy—[Product].[Category].&[Dairy]. The
format of the name is:
[DimensionName].[LevelName].&[MemberKeyName]

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]

5. Click Check to verify that the expression is correct.


x Module 11: Implementing Calculations Using MDX

 To browse Dairy + Meat


1. In the Calculated Member Builder, click OK.
In the Data pane, you see the cube browser retrieving cube data.
2. Scroll to the right of the existing Measures.
Why do you not see the Dairy + Meat calculated member?
The Dairy + Meat calculated member is located in the Product
dimension. Therefore, you must examine the Product dimension to see
Dairy + 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

Demonstration: Creating a Product Average


The following demonstration procedures provide information that will not fit in
Demonstration: the margin notes or is not appropriate for student notes.
15 Minutes
In this demonstration, 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.

 To create a new calculated member


1. In the Cube Editor for the Sales cube, create a new calculated member.
2. In the Parent dimension list, click Product, and then change the Parent
member box value to All Product.
3. Name the new calculated member Average Product Category.
Average Product Category needs to calculate an average value for the
members at the Category level of the Product dimension, across all
measures and all other dimensions.
4. In the Functions list, expand the Numeric folder.
Because the function required for this calculation produces a numeric result,
it is located in the Numeric folder.
5. Click the Avg function.
You see the required syntax for Avg and a short description of the function
in the status box at the bottom of the Calculated Member Builder.
6. Drag Avg to the Value expression box.
The Avg template appears, and includes placeholders for the required and
optional function parameters.

 To define the Set function


1. In the Calculated Member Builder, notice the Avg template:
Avg(«Set»[, «Numeric Expression»])

The chevrons (« ») indicate a placeholder for a function parameter. The


brackets ( [ ] ) indicate an optional function parameter.
2. Remove the optional parameter Numeric Expression, along with the
surrounding brackets:
[, «Numeric Expression»]

Because Average Product Category calculates all measures, you do not


need to specify a numeric expression.
xii Module 11: Implementing Calculations Using MDX

3. The Value expression box contains the following template:


Avg(«Set»)

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.

4. In the Functions box, expand the Set folder.


The Avg function indicates the type of construct required for the
calculation—a Set function. You will define a Set function to finish the Avg
function.
5. Click the function Members – Level in the Set folder.
6. Notice the short description of the function in the Status box:
“Returns the set of all members at a specified level in a dimension.”
You will use the Members – Level function, because it returns the set of all
members at the Category level of the Product dimension.
7. Click the «Set» parameter in the Value expression box.
8. Drag Members – Level to the «Set» parameter.

 To define the Level


1. Expand the Product dimension in the Data box.
Here you see the levels found in the Product dimension. You will define
the level as the Category level, because you want the calculated member to
determine the average of all members in the Category level.
2. Click the «Level» parameter in the Value expression box.
3. Drag the Category level to the «Level» parameter.
4. The Value expression box contains the following expression:
Avg([Product].[Category].Members)

5. Verify that the syntax is correct for Average Product Category.


6. Click OK to close the Calculated Member Builder.

 To browse Average Product Category


1. Find Average Product Category in the cube browser.
2. Verify that the calculation is correct for Average Product Category.
Notice the format applied to the Average Product Category values. The
values are formatted with the currency format string.
3. Save the Sales cube.
Module 11: Implementing Calculations Using MDX xiii

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

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


In addition to performance and the intuitive nature of the multidimensional
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
something between a relational database and a spreadsheet. This is why 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.
After completing this module, you 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.
2 Module 11: Implementing Calculations Using MDX

 Understanding Calculated Members


Topic Objective
To introduce the concept of
calculated members.
Lead-in  Comparing to Spreadsheet Formulas
A key mechanism for  Defining Calculated Members
performing calculations with
Analysis Server is the use of
calculated members.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


A key mechanism for performing calculations with Analysis Server is the use of
calculated members. A calculated member is a dimension member whose value
is based on an expression that is calculated at query time. You typically base
the calculation on existing cube data and other calculated members. You
construct calculated members from arithmetic operators, numeric constants, and
a rich set of built-in functions.
The expressions used to define calculated members employ a language called
multidimensional expressions (MDX). MDX is the query language used by
OLE DB for OLAP and thus Analysis Server. You define calculated members
by using a subset of MDX.
Module 11: Implementing Calculations Using MDX 3

Comparing to Spreadsheet Formulas


Topic Objective
To compare spreadsheet
formulas to calculated
members in OLAP cubes.
Lead-in
In spreadsheets, you define
calculations by using one or
many functions, numeric
computations, and cell
references. In Analysis
Services, you define
calculations by using the
same types of references.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


In spreadsheets, you define calculations by using one or many functions,
numeric computations, and cell references. In Analysis Services, you define
calculations by using the same types of references.
The key difference between spreadsheet calculations and Analysis Services
calculations is that spreadsheet calculations work with a two-dimensional data
space. In Analysis Services, you define calculations across multiple dimensions.
Calculations that span multiple dimensions are difficult to understand when you
work with calculations defined in multidimensional databases.
In the preceding illustration, a spreadsheet defines the calculation, Variance,
which equals Sales minus Forecast. The Variance calculation uses cell
references to define the Sales and Forecast values. In addition, the calculation
uses the minus (-) operator to perform the calculation. As you learn more about
calculated members, notice the similarities between spreadsheet formulas and
calculated members.
4 Module 11: Implementing Calculations Using MDX

Defining Calculated Members


Topic Objective
 Can Belong to Any Dimension
To describe the
characteristics of calculated  Calculate at Query Time
members.
 Do Not Impact Cube Size
Lead-in
Calculated members are  Are Usually Defined by Stored Members
usually calculated  Can Also Be Defined by
measures, or calculations
defined in the Measures  Other calculated members
dimension, leaving many to  Arithmetic operators
believe that a calculated
member must be a  Numeric constants
measure. In fact, a  MDX functions
calculated member can
belong to any dimension.  Can Make Use of External Function Libraries
 Appear as Stored Members to Clients

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


Calculated members are very different from stored dimension members. It is
important to understand the characteristics of calculated members, because
knowing how they perform will help you determine how to use them in cubes.
 Calculated members are usually calculated measures, or calculations
defined in the Measures dimension. Many believe that a calculated member
must be a measure. In fact, a calculated member can belong to any
dimension.
 All calculated members calculate at query time. Only the calculated member
definition is stored on the Analysis Server. The returned values are stored
temporarily in memory.
 Because they calculate in memory at query time, calculated members do not
increase the size of the cube.
 The expressions used to define calculated members typically refer to
existing cube data, or in other words, stored members. For example, a
calculated member named Gross Profit bases itself on two existing
members—Sales minus COGS.
 The definition of a calculated member can also refer to:
• Other calculated members
• Arithmetic operators
• Numeric constants
• A rich set of functions that are part of the MDX language
Module 11: Implementing Calculations Using MDX 5

 In addition to the built-in MDX functions, Analysis Services supports


external function libraries.
• The Microsoft Visual Basic® for Applications function library is
included with Analysis Services.
• The extensive Microsoft Excel function library can be used if Excel is
installed on the client computers and Analysis Server.
• Other third-party function libraries can be used, and custom functions
can be built for use in calculated members.
 To most client front-ends, such as Excel 2000, calculated members do not
appear different from regular members.
6 Module 11: Implementing Calculations Using MDX

Building Calculated Members


Topic Objective
To introduce the Calculated
Member Builder and
describe its components
that assist in creating
calculated members.
Lead-in
The interface for building
calculated members in
Analysis Manager is the
Calculated Member
Builder—a dialog box used
for creating calculated
members in regular and
virtual cubes.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


The interface for building calculated members in Analysis Manager is the
Calculated Member Builder—a dialog box used to create calculated members
in regular and virtual cubes. The Calculated Member Builder interface
simplifies expression construction of calculated members.

Starting the Calculated Member Builder


From inside the Cube and Virtual Cube Editors, you have a variety of ways to
start the Calculated Member Builder:
 On the Insert menu, click Calculated Member.
 Click Insert Calculated Member.
 Right-click the Calculated Members folder, and then click New
Calculated Member.
 Right-click an existing calculated member, and then click Edit.
 Click an existing calculated member, and then, on the Basic tab of the
Properties pane, click Value.
Module 11: Implementing Calculations Using MDX 7

Components of the Calculated Member Builder


The Calculated Member Builder provides various components that assist in
developing expressions:
 Parent dimension. Defines the dimension in which you create the calculated
member. By default, the Parent dimension value is Measures.
 Parent member. Defines the member that is the parent of the calculated
member you create. The calculated member appears below the parent
member in the dimension hierarchy. You enable Parent member when the
Parent dimension selected is not the Measures dimension, and therefore
may contain more than one level in the dimension.

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

Demonstration: Using the Calculated Member Builder


Topic Objective
To demonstrate the
Calculated Member
Builder and the
components used to create
calculated members.
Lead-in
In this demonstration, we
will create a new calculated
member in the Calculated
Member Builder.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


You create calculated members to enhance analysis in cubes and virtual cubes.
Delivery Tips The Calculated Member Builder provides a simple interface for creating
The steps for this
demonstration are included
expressions and assists in developing calculated members.
in the Instructor Notes. In this demonstration, you will learn how to create a calculated member by
Encourage students to
using the Calculated Member Builder.
follow along with your
demonstration.

Tell students that they will


be performing the same
steps later in lab A, Creating
Average Price. If students
follow along with your
demonstration, they can
skip the identical procedures
when they perform the lab.

Explain each component as


you build Average Price
and encourage students to
ask questions.
Module 11: Implementing Calculations Using MDX 9

Lab A: Creating Average Price


Topic Objective
To introduce the lab.
Lead-in
In this lab, you will create a
new calculated member,
Average Price.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


Explain the lab objectives.
Objectives
After completing this lab, you will be able to:
 Work with the Calculated Member Builder.
 Create a simple calculated member.

Prerequisites
Before working on this lab, you must have:
 Experience working with the Cube Editor.
 An understanding of dimensions, cubes, and measures.

Estimated time to complete this lab: 15 minutes


10 Module 11: Implementing Calculations Using MDX

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.

 To restore a new database and define a data source


1. In Analysis Manager, right-click the server, click Restore Database, click
the Look in list, click the file C:\Moc\2074A\Labfiles\L11\Module
11.CAB, click Open, click Restore, and then click Close.
2. Double-click Module 11 to expand the database.
3. Below Module 11, double-click the Data Sources folder, right-click the
Module 11 data source, and then click Edit.
4. Click the Connection tab of the Data Link Properties dialog box, and then
verify that localhost is selected in step 1.
5. In step 2, click Use Windows NT Integrated security.
6. In step 3, click Module 11.
7. Click Test Connection and verify that the test succeeded, click OK, and
then click OK to exit the Data Link Properties dialog box.

 To review Bad Price


1. In the Module 11 database, open the Cube Editor for the Sales cube.
2. Browse the cube in the Data pane.
3. In the cube tree view, click the Bad Price measure.
Notice that Bad Price is a derived measure. What expression is defined for
Bad Price in the Source Column?
"dbo"."SalesFact"."Sales_Dollars" /
"dbo"."SalesFact"."Sales_Units"
____________________________________________________________

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
____________________________________________________________

Bad Price is a derived measure that uses an expression to calculate Sales


Dollars divided by Sales Units. Measures calculate at cube processing time
and aggregate across all dimensions in the cube, based on the Aggregate
Function associated with the measure. Bad Price incorrectly sums its value
across all dimensions.
Instead of creating a derived measure for average price, you will create a
new calculated member that calculates the average. Because calculated
members do not aggregate, you will see correct values for the price.

 To open the Calculated Member Builder


1. In the Cube Editor for the Sales cube, right-click the Calculated Members
folder, and then click New Calculated Member.
The Calculated Member Builder dialog box opens. Here you create and
modify calculated members in Analysis Manager.
2. Notice the Measures dimension in the Parent dimension list.
Having the Measures dimension defined in the Parent dimension list
indicates that the new calculated member resides in the Measures
dimension. You have the option of selecting any of the cube dimensions in
the Parent dimension list. However, do not change Measures.
3. Delete the default name and then type Average Price in the Member name
box.
4. In the Data box, click the plus sign (+) to the left of the Measures
dimension.
Notice the one item, MeasuresLevel, positioned immediately below the
Measures dimension. The fact that Measures contains only one item below
it indicates that Measures contains only one level. All measures dimensions
contain only one level, because they are flat dimensions.
5. Click MeasuresLevel. Notice the status box at the bottom of the
Calculated Member Builder.
The status box contains two lines— Level: MeasuresLevel and
[Measures].[MeasuresLevel]. The first line indicates the object type of
MeasuresLevel. In this instance, MeasuresLevel is a level object. The next
line presents the official name of the object used in calculated member
expressions. In this instance, the official name of the level is
[Measures].[MeasuresLevel].
6. Click the plus sign (+) to the left of MeasuresLevel.
Notice the seven measures below MeasuresLevel. The measures exist in the
one level of the Measures dimension.
7. Click each of the seven measures and notice the object type and official
name of each one.
12 Module 11: Implementing Calculations Using MDX

 To explore other dimensions


1. Click the plus sign (+) to the left of the State dimension.
Notice the four levels in the State dimension—(All), Country, Region, and
State.
2. Expand each of the levels in the State dimension and notice the members
below each level. Compare the State dimension to the Measures
dimension.
3. Notice that you can drill down to lower level members in each of the State
dimension levels.
4. Notice the four property templates below each member that you use to insert
various member properties into expressions.
5. Expand the Time dimension. Notice the two hierarchies in the Time
dimension—Calendar and Fiscal. Expand each of the hierarchies to the
members found at all the levels.
The Calculated Member Builder shows the hierarchy construct in
dimensions and presents hierarchies below dimensions, with the appropriate
levels and members below.

 To create Average Price


1. In the Calculated Member Builder, expand the Measures dimension to the
individual measures.
2. Double-click Sales Dollars.
Notice that [Measures].[Sales Dollars] appears in the Value expression
box. The format of the name is:
[DimensionName].[MemberName]

3. Click the division sign button (/) below the Insert button.
Notice the Value expression box contains the following expression:
[Measures].[Sales Dollars]/

4. Drag Sales Units to the Value expression box, after


[Measures].[Sales Dollars]/

The expression is now:


[Measures].[Sales Dollars]/[Measures].[Sales Units]

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

 To browse Average Price


1. In the Calculated Member Builder, click OK.
In the Data pane, you see the cube browser retrieving cube data.
2. Scroll to the right of Unique Product Count. You see the newly created
calculated member, Average Price.
When you add a new calculated member to a cube, you do not have to
reprocess the cube. The calculated member automatically produces the
correct values, assuming that the calculation expression is correct.
3. In the Calculated Members folder, click Average Price, and then click the
Advanced tab of the properties pane.
4. For the Format String property, click the Currency format.
5. Browse the cube and notice the value of the All Product, All Time, North
American Average Price. What is the value?
$2.17
____________________________________________________________

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

Lab B: Creating Sales Variance Calculations


Topic Objective
To introduce the lab.
Lead-in
In this lab, you will create
two new calculated
members, Sales Variance
and Sales Variance %.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


Explain the lab objectives.
Objectives
After completing this lab, you will be able to:
 Create a simple calculated member.
 Create a calculated member that references another calculated member.

Prerequisites
To complete this lab, you must first complete lab A, Creating Average Price,
found earlier in this module.

Estimated time to complete this lab: 10 minutes


Module 11: Implementing Calculations Using MDX 15

Exercise 1
Creating Sales Variance
In this exercise, you will create a new calculated member, Sales Variance, by
using the Calculated Member Builder.

 To create Sales Variance


1. In the Sales cube, create a new calculated member.
2. Name the calculated member Sales Variance.
3. Define the calculation expression as Sales Dollars minus Projected
Dollars.
4. Check the syntax of Sales Variance to verify that the expression is correct,
and then click OK.

 To verify Sales Variance


1. In the Cube Editor for Sales, browse the cube and notice the Sales Variance
values.
2. Verify that the calculation for Sales Variance is correct.
3. Save the Sales cube.
16 Module 11: Implementing Calculations Using MDX

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.

 To create Sales Variance %


1. In the Sales cube, create a new calculated member.
2. Name the calculated member Sales Variance %
3. Define the calculation expression as Sales Variance divided by Projected
Dollars.
Notice that Sales Variance appears as a measure below the Measures
dimension. You can reference calculated members in expressions of other
calculated members.
4. Check the syntax of Sales Variance % to verify that the expression is
correct, and then click OK.

 To verify Sales Variance %


1. In the Cube Editor for Sales, browse the cube and notice the Sales Variance
% values.
2. Change the Format String property for Sales Variance % to Percent, and
then browse Sales Variance % again to notice the change.
3. Verify that the calculation for Sales Variance % is correct.
4. Save the Sales cube.
Module 11: Implementing Calculations Using MDX 17

Creating Non-Measure Calculated Members


Topic Objective
To introduce the concept of
creating calculated  Common Applications
members in non-Measure
dimensions.  Calculate the difference between two members
Lead-in  Calculate the average of multiple members
Though you created all the
calculated members in lab A
 Create rollups outside of the normal hierarchy
and lab B in the Measures  Aggregation Behavior
dimension, a calculated
member can belong to any  Do not roll up in the parent dimension
dimension.
 Do not affect or add to cube aggregations
 Calculated Member Intersections
 Intersect with every member of every other dimension

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


Though you created all the calculated members in lab A, Creating Average
Price, and lab B, Creating Sales Variance Calculations, in the Measures
dimension, a calculated member can belong to any dimension.

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.

Important It is possible to create calculated members that intersect with other


calculated members. When calculated members intersect, the calculation order
can affect the resulting values. The Solve Order property, discussed later in
this module, is used to prioritize the calculations.
18 Module 11: Implementing Calculations Using MDX

Calculated Member Intersections


Like any other member, a calculated member intersects with every member of
every other dimension.
This means that if you define a calculated member in a dimension other than
Measures, it intersects with each member of the Measures dimension.
Consider a cube with a Region dimension and a Measures dimension,
containing the members shown here:
Region
East
West
East-West Average (calculated member)
Measures
Profit
Sales
COGS
The calculated member East-West Average intersects other dimensions in the
same way as the real members, East and West. It intersects with all three
measures. The intersection is virtual, however, because the calculated member
is not stored in the cube.
This intersection occurs regardless of the type of measure—dollars, units,
percentage, and so on.
When determining the placement of calculated members, consider how the
calculated member intersects with the other dimensions, especially the
Measures dimension. Include a calculated member in a non-Measures
dimension when you want the calculated member to intersect with all the
measures. If it does not seem sensible for the calculated member to intersect
with all measures, the calculated member almost certainly belongs in the
Measures dimension.
Module 11: Implementing Calculations Using MDX 19

Demonstration: Creating a Product Rollup


Topic Objective
To demonstrate how to
create non-Measure
dimension calculated
members.
Lead-in
In this demonstration, you
will learn how to create a
non-Measure dimension
calculated member by using
the Calculated Member
Builder.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


In this demonstration, you will learn how to create a non-Measure dimension
Delivery Tips calculated member by using the Calculated Member Builder.
The steps for this
demonstration are included
in the Instructor Notes.
Encourage students to
follow along with your
demonstration.

Tell students that they will


be performing the same
steps later in lab C, Creating
Non-Measure Dimensions. If
students follow along with
your demonstration, they
can skip the identical
procedures when they
perform the lab.

Explain each component as


you build Dairy + Meat and
encourage students to ask
questions.
20 Module 11: Implementing Calculations Using MDX

Lab C: Creating a Non-Measure Dimension


Topic Objective
To introduce the lab.
Lead-in
In this lab, you will create a
non-Measure dimension
calculated member.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


Explain the lab objectives.
Objectives
After completing this lab, you will be able to:
• Create a calculated member in the Time dimension.

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.

Estimated time to complete this lab: 10 minutes


Module 11: Implementing Calculations Using MDX 21

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.

 To create a new calculated member


1. In the Cube Editor for the Sales cube, create a new calculated member.
2. In the Parent dimension list, click Time.Calendar.
The calculated member will reside in the Time.Calendar dimension.
3. Leave the Parent member box empty.
The new calculated member will exist at the same level as All Time.

 To define the calculation


1. In the Calculated Member Builder, delete the default name and name the
new calculated member Time Variance
2. Define the calculation as 2001 minus 2000.
[Time].[Calendar].[Year].&[2001]-
[Time].[Calendar].[Year].&[2000]
3. Click Check and make changes to the expression until it is correct and then
click OK.

 To browse Time Variance


1. In the Calculated Member Builder, click OK.
In the Data pane, you see the cube browser retrieving cube data.
2. Find Time Variance in the cube browser.
3. Verify that the calculation is correct for Time Variance.
4. Save the Sales cube.
22 Module 11: Implementing Calculations Using MDX

Using Functions within Calculated Members


Topic Objective
To discuss functions and
their use in calculated
members.  Used for Complex Calculations
Lead-in  Included in the Calculated Member Builder
The MDX language contains
a rich library of functions  Located in Specific Folders
that are available to create
complex calculated
members.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


You have seen how to use simple arithmetic operators and members to define
calculated members. In addition to these simple expressions, the MDX
language contains a rich library of functions that are available to create complex
calculated members.
You create calculated members in the Calculated Member Builder. In the
Calculated Member Builder, the Functions list contains several folders. Each
folder contains MDX functions used to create calculated members.
When searching for functions in the Functions list, ask the question, “What
data or object type does the function return?” If the function returns a number,
you can find the function in the Numeric folder. If it returns a string, you can
find the function in the String folder.
Module 11: Implementing Calculations Using MDX 23

Demonstration: Creating a Product Average


Topic Objective
To demonstrate the use of
functions in calculated
members.
Lead-in
In this demonstration, you
will learn how to create a
calculated member by using
MDX functions.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


In this demonstration, you will learn how to create a calculated member by
Delivery Tips using MDX functions.
The steps for this
demonstration are included
in the Instructor Notes.
Encourage students to
follow along with your
demonstration.

Tell students that they will


be performing the same
steps later in lab D, Creating
Calculated Members with
Functions. If students follow
along with your
demonstration, they can
skip the identical procedures
when they perform the lab.

Explain each component as


you build Average Product
Category and encourage
students to ask questions.
24 Module 11: Implementing Calculations Using MDX

Lab D: Creating Calculated Members with Functions


Topic Objective
To introduce the lab.
Lead-in
In this lab, you will create
non-Measure dimension
calculated members that
use MDX functions.

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


Explain the lab objectives.
Objectives
After completing this lab, you will be able to:
 Create a calculated member that uses the Avg function.
 Create a calculated member that uses the Sum function.

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.

Estimated time to complete this lab: 10 minutes


Module 11: Implementing Calculations Using MDX 25

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.

 To create a new calculated member


1. In the Cube Editor for the Sales cube, create a new calculated member.
2. In the Parent dimension list, click Product, and then change the Parent
member box value to All Product.
3. Name the new calculated member Average Product Category
Average Product Category needs to calculate an average value for the
members at the Category level of the Product dimension, across all
measures and all other dimensions.
4. In the Functions list, expand the Numeric folder.
Because the function required for this calculation produces a numeric result,
it is located in the Numeric folder.
5. Click the Avg function.
You see the required syntax for Avg and a short description of the function
in the status box at the bottom of the Calculated Member Builder.
6. Drag Avg to the Value expression box.
The Avg template appears, and includes placeholders for the required and
optional function parameters.

 To define the Set function


1. In the Calculated Member Builder, notice the Avg template:
Avg(«Set»[, «Numeric Expression»])

The chevrons (« ») indicate a placeholder for a function parameter. The


brackets ( [ ] ) indicate an optional function parameter.
2. Remove the optional parameter Numeric Expression, along with the
surrounding brackets:
[, «Numeric Expression»]

Because Average Product Category calculates all measures, you do not


need to specify a numeric expression.
26 Module 11: Implementing Calculations Using MDX

3. The Value expression box contains the following template:


Avg(«Set»)

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.

4. In the Functions box, expand the Set folder.


The Avg function indicates the type of construct required for the
calculation—a Set function. You will define a Set function to finish the Avg
function.
5. In the Set folder, click the function Members – Level.
6. Notice the short description of the function in the Status box:
“Returns the set of all members at a specified level in a dimension.”
You will use the Members – Level function, because it returns the set of all
members at the Category level of the Product dimension.
7. Click the «Set» parameter in the Value expression box.
8. Drag Members – Level to the «Set» parameter.

 To define the Level


1. Expand the Product dimension in the Data box.
Here you see the levels found in the Product dimension. You will define
the level as the Category level, because you want the calculated member to
determine the average of all members in the Category level.
2. Click the «Level» parameter in the Value expression box.
3. Drag the Category level to the «Level» parameter.
4. The Value expression box contains the following expression:
Avg([Product].[Category].Members)

5. Verify that the syntax is correct for Average Product Category.


6. Click OK to close the Calculated Member Builder.

 To browse Average Product Category


1. Find Average Product Category in the cube browser.
2. Verify that the calculation is correct for Average Product Category.
Notice the format applied to the Average Product Category values. The
values are formatted with the currency format string.
3. Save the Sales cube.
Module 11: Implementing Calculations Using MDX 27

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.

 To create a new calculated member


1. In the Cube Editor for the Sales cube, create a new calculated member.
2. In the Parent dimension list, click Time.Calendar.
The calculated member will reside in the Time.Calendar dimension.
3. Leave the Parent member box empty.
The new calculated member will exist at the same level as All Time.
4. Name the new calculated member Total Quarter
Total Quarter will be used to test the All Time total. It needs to sum all
members at the Quarter level of the Time.Calendar dimension, across all
measures and all other dimensions.
5. In the Functions list, expand the Numeric folder.
6. Click the Sum function.
You see the required syntax for Sum and a short description of the function
in the status box at the bottom of the Calculated Member Builder.
7. Drag Sum to the Value expression box.

 To define the Set function


1. In the Value Expression box, remove the optional parameter Numeric
Expression, along with the surrounding brackets:
[, «Numeric Expression»]

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

 To define the Level


1. Expand the Time dimension, and the Calendar hierarchy in the Data box.
2. Click the «Level» parameter in the Value expression box.
3. Drag the Quarter level to the «Level» parameter.
4. The Value expression box contains the following expression:
Sum([Time].[Calendar].[Quarter].Members)

5. Verify that the syntax is correct for Total Quarter.


6. Close the Calculated Member Builder.

 To browse Total Quarter


1. Find Total Quarter in the cube browser.
2. Verify that the calculation is correct for Total Quarter by comparing it to
the value of All Time across all measures and dimensions.
3. Save the Sales cube.
4. Close the Cube Editor.
Module 11: Implementing Calculations Using MDX 29

Understanding Other Calculation Methods


Topic Objective
To describe three other  Custom Rollup Formulas
methods of defining
calculations in Analysis  Override the Aggregate Function properties across a dimension
level
Services.
 Apply to all members of a level
Lead-in
Analysis Services provides  Custom Member Formulas
a variety of methods for
defining calculations by  Replace the definition of a single member without affecting other
using MDX. members
 Enable members to aggregate with the other dimension members
 Calculated Cells
 Supply data values to existing cube cells based on MDX logic
 Allow for specific calculation scope and logic

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


There are calculation methods other than the creation of calculated members.
Delivery Tips Analysis Services provides a variety of methods for defining calculations by
Quickly describe each type
of calculation, but do not
using MDX.
spend too much time here.
The calculations are outside Note For more information on other calculation methods, refer to SQL Server
the scope of this course, Books Online or see course 2093A, Implementing Business Logic with MDX in
and you should therefore Microsoft SQL Server 2000.
refer students to course
2093A, Implementing
Business Logic with MDX in
Microsoft SQL Server 2000 Custom Rollup Formulas
and SQL Server Books You create custom rollup formulas in dimensions by using MDX expressions.
Online for more information. The following list describes custom rollup formulas:

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

The expression references the last child, or Quarter 4, of the


CurrentMember, or the current year. Now, the value for each Year is
equal to the value for its Quarter 4 child.
 The MDX calculations defined for custom rollup formulas apply to all
members in the specified level.
30 Module 11: Implementing Calculations Using MDX

 You create custom rollup formulas by updating level properties in the


Dimension Editor or Cube Editor, depending on whether the dimension is
shared or private.
• You update the Custom Rollup Formula property for lower levels of a
dimension.
• You update the All Member Formula property for the All level of a
dimension.
 You cannot use a custom rollup formula in a cube containing a Distinct
Count measure.

Custom Member Formulas


You use a custom member formula to define a calculation for a member across
all dimensions in a cube. The following list describes custom member formulas:
 A custom member formula allows you to replace the definition of a single
member of a dimension without affecting any other members in the
dimension.
 Custom member formulas override the Aggregate Function properties
defined for the cube measures across a dimension member.
 Custom member formulas are calculations developed by using MDX, like
custom rollup formulas.
 You use custom member formulas when you need individual members to
aggregate differently from the standard Aggregate Function properties
defined for measures.
For example, in an Account dimension, you can define the calculation for
Gross Sales in one cube as being equal to a Sales value from another cube,
by using the LookUpCube MDX function.
Because you want only Gross Sales to use this calculation, you define the
calculation as a custom member formula instead of a custom rollup formula.
The value for Gross Sales is then included in any cube aggregations.
 Custom member formulas are stored in the dimension table.
• You can use an existing column in the dimension table to store the
member formulas.
• You can create a new column in the dimension table and can update the
dimension in Analysis Manager if the dimension is write-enabled.
Otherwise, you must update the table through an interface other than
Analysis Manager.
 Because the member is defined in the dimension table, it participates in any
aggregations or rollups defined in the cube.
 You enable custom member formulas by updating level properties in the
Dimension Editor or Cube Editor, depending on whether the dimension is
shared or private.
• You update the Custom Members property for levels of a dimension.
 The MDX calculations defined for custom member formulas apply to the
specified member across all dimensions.
 If a level contains a custom rollup formula and custom member formulas,
the custom member formulas will override the custom rollup formula.
Module 11: Implementing Calculations Using MDX 31

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

Introducing Solve Order


Topic Objective
To discuss the importance Sales $ Units Sales $ / Units
of setting Solve Order for
calculated members.
Bread 100 150 0.67
Lead-in
Dairy 100 75 1.33
The Solve Order feature in Meat 300 75 4.00
Analysis Services allows
you to specify the order in Dairy + Meat 400 150 2.67
which calculations execute.
Sales $ Units Sales $ / Units
Bread 100 150 0.67
Dairy 100 75 1.33
Meat 300 75 4.00
Dairy + Meat 400 150 5.33

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


The Solve Order property in Analysis Services allows you to specify the order
Delivery Tips in which calculations execute.
Present this build slide in
the following order: In the preceding illustration, two calculations exist in the cube—Average Sales
1. Explain that the two and Dairy + Meat. Average Sales equals Sales divided by Units, and Dairy +
spreadsheets demonstrate
Meat equals Dairy plus Meat.
two orders of calculation for
the same data values. Because the two calculations exist in separate dimensions, Measures and
2. Sequentially explain the Product, the calculations intersect. The two calculations define the intersection:
calculations in the top
spreadsheet, with Dairy +  Dairy + Meat
Meat calculating first.
3. Next, sequentially explain  Sales / Units
the calculations in the
bottom spreadsheet, with If the Dairy + Meat member calculates before the Average Sales member, the
Average Sales calculating intersection result is equal to $2.67. The calculation steps are as follows:
first.
4. Ask students which 1. Dairy + Meat for Sales = 400
calculation they prefer. They
2. Dairy + Meat for Units = 150
should say the top
calculation. 3. (Dairy + Meat for Sales) / (Dairy + Meat for Units) = 400 / 150 = 2.67
5. Finally, explain that you
set the calculation order by
using the Solve Order
property, and describe
where and how to define it
in the Cube Editor.
Module 11: Implementing Calculations Using MDX 33

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.

Setting Solve Order


Solve Order can be set on the Advanced tab of the calculated member
Properties pane in the Cube Editor. This is the only place in Analysis Manager
where you can set Solve Order.
Following are characteristics of the Solve Order:
 The Solve Order property accepts an integer value that determines the
priority for solving the formula.
 The higher the integer of Solve Order for a calculated member, the later the
member calculates.
 A Solve Order value of 1 calculates after a Solve Order of 0. Solve Order
2 calculates after Solve Order 1, and so on.

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

*****************************ILLEGAL FOR NON-TRAINER USE*****************************


1. How does a calculated member differ from a derived measure?
A calculated member is not stored in the cube, but a derived measure is
stored in the cube.
A calculated member uses MDX to perform calculations, and a derived
measure uses SQL.
When you add a calculated member to a cube, you do not need to
process the cube. You must reprocess the cube after adding a derived
measure.
Derived measures must exist in the Measures dimension. Calculated
members can exist in any dimension.
You can only have 1,024 derived measures. You can have 65,535
calculated members.
Calculated members do not aggregate and derived measures do
aggregate.

2. Do calculated members increase cube size?


No, only cube metadata size.

3. When you add a calculated member to a cube, must the cube be


reprocessed?
No.
Module 11: Implementing Calculations Using MDX 35

4. Can SQL expressions be used to define a calculated member?


No.

5. What types of cube calculations use MDX?


Calculated members, custom rollup formulas, custom member
formulas, and calculated cells use MDX.

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

You might also like