Tải bản đầy đủ (.pdf) (78 trang)

Module 6: Creating and Manipulating Sets

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.16 MB, 78 trang )




Contents
Overview 1
Using Set Creation Functions 2
Lab A: Using Set Creation Functions 13
Using Set Manipulation Functions 20
Lab B: Using Set Manipulation Functions 30
Using Subquery Set Functions 36
Lab C: Using Subquery Set Functions 52
Working with Dimension Interactions 57
Lab D: Working with Dimension
Interactions 64
Review 67


Module 6: Creating and
Manipulating Sets
BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
to represent any real individual, company, product, or event, unless otherwise noted. Complying
with all applicable copyright laws is the responsibility of the user. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation. If, however, your only
means of access is electronic, permission to print one copy is hereby granted.

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.

 2000 Microsoft Corporation. All rights reserved.

Microsoft, BackOffice, MS-DOS, Windows, Windows NT, <plus other appropriate product
names or titles. Replace this example list with list of trademarks provided by copy editor.
Microsoft is listed first, followed by all other Microsoft trademarks in alphabetical order. > are
either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other
countries.

Content developed by OLAP Train, Inc. for Microsoft Corporation and distributed under license.

The names of companies, products, people, characters, and/or data mentioned herein are fictitious
and are in no way intended to represent any real individual, company, product, or event, unless
otherwise noted.

Other product and company names mentioned herein may be the trademarks of their respective
owners.


Module 6: Creating and Manipulating Sets iii

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Instructor Notes
The ability to work with sets is critical both to retrieving data from an online
analytical processing (OLAP) cube in a multidimensional expression (MDX)
query statement and creating powerful MDX expressions.
In this module, students will be introduced to functions that return sets of

members. Some of the functions retrieve sets from the metadata defined in the
cube's dimensions. Some of the functions manipulate those sets to create new
sets that meet specific analytical purposes.
After completing this module, students will be able to:
!
Use functions to create a set.
!
Use functions to manipulate a set.
!
Create a set from subqueries.
!
Manipulate dimension interactions by using advanced functions.
Materials and Preparation
This section provides you with the required materials and preparation tasks that
are needed to teach this module.
Required Materials
To teach this module, you need the following materials:
!
Microsoft
®
PowerPoint
®
file 2093A_6.ppt

Preparation Tasks
To prepare for this module, you should:
!
Read all of the materials for this module.
!
Read the instructor notes and margin notes.

!
Practice the lecture and demonstrations.
!
Complete the labs.
!
Review the Teacher Preparation materials on the Teacher Preparation
compact disc.

Presentation:
95 Minutes

Labs:
75 Minutes
iv Module 6: Creating and Manipulating Sets

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY


Instructor Setup for Group Activities and Labs
This section provides setup instructions that are required to prepare the
instructor computer or classroom configuration for group activities and labs.
All group activities and labs use the same database setup, which requires
restoring a database archive.
!
To prepare for group activities and labs
In this procedure, you restore the Market database, which is a .cab file type.
1. Open Analysis Manager.
2. In the left pane, expand the Microsoft Analysis Services folder.
3. Expand the Server icon and verify that the Market database does not exist.
4. Right-click the Server icon, and then click Restore Database.

5. Navigate to the C:\Moc\2093A\Batches folder.
6. Select Market.cab, click Open, and then click Restore.

If the Market database already exists from a previous group exercise or lab,
and cubes within the database contain extraneous information, you can return
the Market database and its cubes to a beginning position by either:
Deleting any calculated members that were created in a specific cube, and then
saving the cube.
- or -
Repeating the preceding restore database procedure.

Module 6: Creating and Manipulating Sets v

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

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. Do the Members, Children, and Descendants function really create sets?
These functions begin with something that is not a set—a dimension, a
level, or a member—and return something that is a set. In that sense,
they create sets. This is different from most other set functions, which
begin with one or more sets and return a different set.

2. How would you get all the leaf-level members of an entire dimension?
Use the Descendants function with the All Level member as the
common ancestor.


3. Why do some functions—such as Children—follow a member while other
functions—such as Descendants—include the member as an argument? In
Microsoft Visual Basic
®
terminology, why are some functions treated as
properties while others are treated as methods?
MDX functions do come in two forms: those that follow an object—
properties; and those that take arguments—methods. There is no
obvious reason for the difference. As a general rule, property-style
functions don’t take arguments, whereas method-style functions usually
do, but there are exceptions. As you learn a new function, you must
remember its syntactic form.

4. The optional flags for the Descendants function can be confusing. Is there
an easy way to learn them?
In the first place, you can usually avoid using the flags of the
Descendants function if you are willing to use combinations of other
functions—particularly Union, Except, and Hierarchize. If you do want
to use the Descendants flags, replace “before” with “above,” and
“after” with “below,” and read the arguments in the order 1, 3, 2. For
example, read the expression Descendants([1998],[Calendar
Quarter],BEFORE_AND_AFTER) as “the descendants of 1998 above
and below the calendar quarter level.”

5. The function definitions in the Syntax Examples list of the MDX2093A
application do not always match those in the Functions list of the Calculated
Member Builder. Which are correct?
The MDX2093A application is simply a learning tool. It has many
imperfections. Always use the Calculated Member Builder or Books

Online to find and learn unfamiliar functions.
vi Module 6: Creating and Manipulating Sets

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

6. In both Books Online and the Functions list of the Calculated Member
Builder, the syntax for the Descendants – Level function shows that you
cannot use the third argument—Desc_flags—without also using the second
argument—Level. Is that true?
No. You can omit the Level argument, leaving commas to show its
place, and still use a flag such as LEAVES as the third argument. The
documentation is incorrect.

7. What are the different ways you can join together two sets, and what are the
differences between them?
There are three ways to combine two sets: the Union function, the plus
operator (+), and simply enclosing the sets in braces. The plus operator
requires an extra set of braces anyway, and there is no difference
between using commas or plus signs to separate sets. The Union
function can combine only two sets at a time, but it defaults to strip
duplicate members. If you do want duplicate members, it may be easier
to just combine the sets with braces. If you want to strip duplicate
members, you may want to use the Union function.

8. Would you ever use the NON EMPTY keyword to create a calculated
member?
No. It is used only to create a query statement that returns a report. In
a calculated member, you can use the NonEmptyCrossjoin function to
combine sets from multiple dimensions and remove tuples that produce
an empty result.



Module 6: Creating and Manipulating Sets vii

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Module Strategy
Major sections of this module begin with or include a group activity followed
by review lecture and then labs. The following are guidelines for delivering
materials in the context of group activities:
!
Using group activities to introduce new content
You often introduce new concepts or functionality while delivering the
procedures in a group activity as a live demonstration. For example, you
may present a new MDX function by showing first its construction and then
its result set as an actual calculated member formula or within a query
statement.
Use the topic slides that follow the group activity as a review of the
content—for example, the syntax of a specific function.
!
Interaction with students
A group activity flows best when you deliver it as a shared exploration. Ask
students such questions as: “What would happen if we…?” “Why did this
happen?” “Was that what you expected?” Encourage students to ask you
questions about the functions being tested.
!
Students follow along
In some cases, you may want to encourage students to follow your live
demonstration on their own computers. This practice works best for simpler
group activities or for a group activity that is not replicated by a later lab.

It is not a problem if a student does not follow your demonstration, or if a
student starts following and then stops before the group activity is
completed. There is no file or structure dependency between group activities
or between a group activity and a later lab.
!
Lab replication of group activity
The exercises in the labs closely follow the group activity procedures but do
not define each step or show the code answer. Encourage students to write
and test the MDX expressions on their own, referring back to the group
activity procedures for clarification. Students may also refer to answer files,
which are available for each procedure in exercises.
Labs are generally more challenging when students have not followed the
instructor on their own computers during the group activity. However, many
students benefit from the two hands-on experiences of following the group
activity and then completing the labs.
!
Answer files for group activities
Where applicable, answer files are provided for each procedure in group
activities. If necessary to facilitate your demonstration, copy and paste the
correct expression from the answer file into the Calculated Member Builder.

viii Module 6: Creating and Manipulating Sets

BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Use the following additional strategies to present this module:
!
Using Set Creation Functions
Begin by explaining why it is important to be able to create a set of
members. Next, describe the use of the Members function, explaining the

syntax carefully. Then introduce the Descendants function, describing how
it can be used to retrieve members from either a single level or from
multiple levels. Emphasize the fact that these functions are returning
metadata about the cube, not data from the cube.
!
Using Set Manipulation Functions
Explain why it is useful to be able to manipulate sets to create a new set that
contains specific members. Introduce the Head, Tail, Union, Intersect,
Except, and Hierarchize functions, describing the syntax for each and
giving examples of when to use each function.
!
Using Subquery Set Functions
Define the term subquery and describe when a subquery is used. Emphasize
the difference between functions that look only at cube metadata and
functions that use a subquery to retrieve actual data form the cube, although
the function returns only a set of members and no actual data.. Introduce the
Order, TopCount, and Filter functions, describing the syntax for each and
explaining when to use each function.
!
Working with Dimension Interactions
Explain that this section introduces more advanced processes that retrieve
sets that combine members from two or more dimensions. Then introduce
the Crossjoin function and the NON EMPTY keyword. Describe the
syntax for each and explain when to use each.
Module 6: Creating and Manipulating Sets 1


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Overview

!
Using Set Creation Functions
!
Using Set Manipulation Functions
!
Using Subquery Set Functions
!
Working with Dimension Interactions


The ability to work with sets is critical both to retrieving data from an online
analytical processing (OLAP) cube in a multidimensional expression (MDX)
query statement and creating powerful MDX expressions.
In this module, you will be introduced to functions that return sets of members.
Some of the functions retrieve sets from the metadata defined in the cube's
dimensions. Some of the functions manipulate those sets to create new sets that
meet specific analytical purposes.
After completing this module, you will be able to:
!
Use functions to create a set.
!
Use functions to manipulate a set.
!
Create a set from subqueries.
!
Manipulate dimension interactions by using advanced functions.

Topic Objective
To provide an overview of
the module topics and

objectives.
Lead-in
In this module, you will learn
about the creation and
manipulation of sets.
2 Module 6: Creating and Manipulating Sets


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

#
##
#

Using Set Creation Functions
!
Group Activity: Using Set Creation Functions
!
Members Function
!
Children Function
!
Single-Level Descendants Function
!
Leaf-Level Descendants Function


In this section, you will learn the most useful functions for retrieving a set of
members from the metadata of a cube. These functions, when used alone,
retrieve only sets of members from the cube metadata, not actual data from the

cube. These sets can appear as labels on the axes of a report, controlling which
cube values appear.
In later sections, you will learn how to manipulate these simple sets of
members.
The group activity introduces the use of two basic functions that generate sets—
the Members function and the Descendants function. The following topics
follow the group activity:
!
Members Function
This topic describes how to return members of specified levels and
dimensions by using the Members function.
!
Children Function
This topic describes the Children function. This function returns the
children of a specified member.
!
Single-Level Descendants Function
This topic describes the Descendants function. The simplest form of this
function returns a set of members at a specific level, lower in the hierarchy
tree than the member and level names given in the query. You can also use
the Descendants function to return all the members that descend from a
single member.
!
Leaf-Level Descendants Function
The Descendants function can also be used to return a set of members from
the lowest level of a dimension—the leaf-level members. To return a set that
includes only leaf-level members, you use an optional third argument in the
Descendants function.

Topic Objective

To introduce functions that
retrieve a set of members
from the metadata of a
cube.
Lead-in
In this section, you will learn
the most useful functions for
retrieving a set of members
from the metadata of a
cube.
Delivery Tip
Briefly explain the bullets on
this diamond slide to provide
context for the upcoming
group activity in which the
items are functionally
demonstrated.
Module 6: Creating and Manipulating Sets 3


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Group Activity: Using Set Creation Functions



In this group activity, you may follow along on your own computer with your
instructor or observe the demonstration
You will learn how to generate sets by using the Members and Descendants
functions. Once you understand these functions, you can easily learn other

related functions.
!
To open the MDX2093A application and template file
In this procedure, you use the MDX2093A sample application to open
templates you will use in the remainder of the group activity.
1. In Microsoft
®
Windows
®
Explorer, navigate to C:\MOC\2093A\LabFiles,
double-click MDX2093A.exe, and then click OK to connect to the server.
2. When asked to open a query file, navigate to the folder
C:\MOC\2093A\LabFiles\L06, and open the file SetCreate.mdx.
3. In the DB list, select Market, and then in the Cube list, select Sales. The
first template looks like the following text:
--Members of a Dimension
-------------------------------------
SELECT
{[Sales Dollars], [Sales Units]} ON COLUMNS,
«Set» ON ROWS
FROM Sales


Topic Objective
To learn how to create sets
by using the Members and
Descendants functions.
Lead-in
In this group activity, you will
learn how to generate sets

of members.
Delivery Tip
Explain initial template
before continuing with the
group activity.
4 Module 6: Creating and Manipulating Sets


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

!
To show all the members of a dimension
In this procedure, you use the Members function to create a set that
consists of all members of all levels of a dimension.
1. Click in the «Set» token of the Members of a Dimension query. In the
Syntax Examples list, expand the Set folder, and then double-click
Members – Dimension.
MDX includes three different Member functions: one each for Level,
Dimension, and Hierarchy. The Dimension and Hierarchy versions are
essentially identical: simply think of the dimension and hierarchy together
as the name of the dimension.
2. Click in the «Dimension» token, and then in the Data list, double-click the
Product dimension. The resulting statement looks like this:
SELECT
{[Sales Dollars], [Sales Units]} ON COLUMNS,
[Product].Members ON ROWS
FROM Sales

3. To view the results of the query, click the Run Query button.


The labels on the Rows axis appear from all levels of the Product
hierarchy. The member names in a level are sorted according to the Order
By Column property defined in the dimension.

The MDX2093A application displays members from multiple levels in a
single column, but indented. This differs from the browser in the Analysis
Manager and the Microsoft Office PivotTable
®
list, which use a separate
column for each level. It is the client application—not the MDX statement—
that determines how levels are displayed.


!
To show the children of a member
In this procedure, you use the Children function to create a set that consists of
members that are the children of a specified member.
1. In the Queries list, select Children of a Member.
2. Click in the «Set» token. In the Syntax Examples list, expand the Set
folder, and then double-click Children.
The Children function must follow a single member. Do not confuse the
Children function with the Members function. A member has children. A
level or a dimension has members.
Delivery Tip
CreateDimensionD.txt in
C:\MOC\2093A\Demo\D06\
Answers contains the
completed MDX expression
for this procedure.
Note

Delivery Tip
CreateChildrenD.txt in
C:\MOC\2093A\Demo\D06\
Answers contains the
completed MDX expression
for this procedure.
Module 6: Creating and Manipulating Sets 5


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

3. Click in the «Member» token and then type [Bagels] The resulting
statement looks like this:
SELECT
{[Sales Dollars],[Sales Units]} ON COLUMNS,
Bagels.Children ON ROWS
FROM Sales

4. To view the results of the query, click the Run Query button.

The Rows axis contains the five members that have Bagels as a parent.

The Children function is analogous to the Parent function. The Parent
function goes up the tree, whereas the Children function goes down the tree.
The Parent function returns a member, whereas the Children function returns
a set. That is because a member can have more than one child, but a member
never has more than one parent.


!

To show single-level descendants of a member
In this procedure, you use the Descendants function to create a set of members
that are all descendants of one specified member.
1. In the Queries list, select Descendants at a Level.
2. Click in the «Set» token. In the Syntax Examples list, expand the Set
folder, and then double-click Descendants.
3. Remove brackets around optional arguments, and then delete the third
argument.
The first argument is a member. It is the common ancestor for all the
members returned by the function.
4. Click in the «Member» token and type [Bread]
The second argument is a level. It is the level from which you want to
retrieve members.
5. Click in the «Level» token and type [Product Name]. The resulting
statement looks like this:
SELECT
{[Sales Dollars],[Sales Units]} ON COLUMNS,
Descendants([Bread],[Product Name]) ON ROWS
FROM Sales

Note
Delivery Tip
CreateDescendantsLevelD.t
xt in
C:\MOC\2093A\Demo\D06\
Answers contains the
completed MDX expression
for this procedure.
6 Module 6: Creating and Manipulating Sets



BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

6. To view the results of the query, click the Run Query button.

The set of members on the Rows axis comes from the Product Name level
but includes only those products that share Bread as a common ancestor.

The Descendants function is analogous to the Ancestor function—that
is, in both cases you can specify a starting member and a level. As with the
Ancestor function, you can specify the level for the Descendants function by
using either an explicit level name or a relative numeric value that gives the
distance or number of levels to skip.


!
To show all the descendants of a member
In this procedure, you use the Descendants function to create a set of all the
members that are descendants of a specified member.
1. In the Queries list, select All Descendants.
2. Click in the «Set» token. In the Syntax Examples list, expand the Set
folder, and then double-click Descendants.
3. Delete everything except the first argument.
If you include only the common ancestor member in the Descendants
function, it returns all the descendants of that member at all remaining levels
of the hierarchy.
4. Click in the «Member» token and type [Bread] The resulting statement
looks like this:
SELECT
{[Sales Dollars],[Sales Units]} ON COLUMNS,

Descendants([Bread]) ON ROWS
FROM Sales

5. To view the results of the query, click the Run Query button.

The set on the Rows axis contains all the members of the Product
dimension that share Bread as a common ancestor.

Note
Delivery Tip
CreateDescendantsAllD.txt
in
C:\MOC\2093A\Demo\D06\
Answers contains the
completed MDX expression
for this procedure.
Module 6: Creating and Manipulating Sets 7


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

!
To create a set of the leaf-level descendants of a member
In this procedure, you use the Descendants function to create a set of the leaf-
level members of a parent-child dimension. In a parent-child dimension, leaf-
level members—members that have no children—are not always on the same
level.
1. In the Queries list, select Leaf-Level Descendants.
2. Click in the «Set» token. In the Syntax Examples list, expand the Set
folder, double-click Descendants, and then delete any brackets indicating

optional arguments.
3. Click in the «Member» token, and then in the Data list, double-click the
Employee dimension.
Using only the dimension name in a context that requires a member gives
you the current member of the dimension. In this context, the current
member is the default member, which for the Employee dimension is the
CEO.
4. In the second argument, delete the «Level» token but leave the commas that
surround it.
Omitting the Level argument yields all the descendants of the specified
member at all levels. The third argument is a flag that indicates what kind of
descendants you want.
5. Click in the «Desc_flags» token, and then type LEAVES. The resulting
statement looks like this:
SELECT
{[Sales Dollars],[Sales Units]} ON COLUMNS,
Descendants(Employee, , LEAVES) ON ROWS
FROM Sales

6. To view the results of the query, click the Run Query button.

The set of members on the Rows axis consists of all the leaf-level members
of the Employee dimension, although those members occur on different
levels. None of the summarized members appears in the set.

Delivery Tip
CreateDescendantsLeaves
D.txt in
C:\MOC\2093A\Demo\D06\
Answers contains the

completed MDX expression
for this procedure.
8 Module 6: Creating and Manipulating Sets


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Members Function
!
Returns a Specified Set of Members
!
Retrieves All Members of a Level or Dimension
!
Must Use Hierarchy Version If the Dimension Has
Explicit Hierarchy
[Time].[Quarters].Members
[Time].[Quarters].Members
[Time].[Fiscal].Members
[Time].[Fiscal].Members
[Product].Members
[Product].Members
Returns the Members of the Quarters
Level of the Time Dimension
Returns the Members of the Quarters
Level of the Time Dimension
Returns the Members of the Product
Dimension
Returns the Members of the Product
Dimension
Returns the Members of the Fiscal

Hierarchy of the Time Dimension
Returns the Members of the Fiscal
Hierarchy of the Time Dimension


The Members function returns members of the specified levels and
dimensions.
The following example returns the members of the Quarters level of the Time
dimension.
[Time].[Quarters].Members

The following example returns the members of the Product dimension.
[Product].Members

The following example returns the members of the Fiscal hierarchy of the Time
dimension.
[Time].[Fiscal].Members

When you use the Members function, consider the following facts and
guidelines:
!
The Members function works not only with the members of a level, but can
also be used to retrieve all the members of a dimension.

When you have a large dimension, retrieving all the members of
the dimension can create a very large set. Use caution when you use the
Members function with a dimension.

!
In the Set group of the Functions list, the Members – Hierarchy function

appears. This means that if a dimension has a hierarchy—for example, the
Time dimension, which has Calendar and Fiscal hierarchies—you must
use the entire Dimension.Hierarchy name.
!
Because the Members function returns a set of members, it appears in the
Set group of the Syntax Example list.
Topic Objective
To explain the syntax and
results of the Members
function.
Lead-in
The Members function
returns members of specific
levels or dimensions.
Example 1
Example 2
Example 3
Delivery Tip
Because students have
already been exposed to the
Members function in the
previous group activity, treat
this topic as a review—that
is, do not spend a lot of
time.
Caution
Module 6: Creating and Manipulating Sets 9


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY


MDX includes the following other functions that return sets similar to the
Members function:
!
The AllMembers function returns all the members of a level or dimension,
including any calculated members.
!
The AddCalculatedMembers function adds any calculated members to a
set.
!
The StripCalculatedMembers function removes any calculated members
to a set.
You can find more information about these functions by searching on the
function name in Microsoft SQL Server

Books Online.
Related Functions
Delivery Tip
These related functions are
included for reference only.
Do not spend any time
explaining them.
10 Module 6: Creating and Manipulating Sets


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Children Function
!
Returns a Set of Children of a Member

!
Is Similar to the Parent Function
$
Moves down the tree instead of up
$
Returns a set instead of a single member
!
Is Easy to Confuse with Members Function
!
Appears in the Set Group of the Syntax Examples List
[1998].Children
[1998].Children
Returns the set of all quarters in 1998
Returns the set of all quarters in 1998


The Children function returns members that have the specified member as a
parent.
The following example returns all the quarters in 1998.
[1998].Children

When you use the Children function, consider the following facts and
guidelines:
!
The Children function is analogous to the Parent function. There are two
main differences:
• The Children function moves down the tree, whereas the Parent
function moves up.
• The Children function returns a set, whereas the Parent function
returns a single member.

!
The Children function is easy to confuse with the Members function
because both return a set of members. Following are the important
differences:
• A level (or dimension) has Members.
• A member has Children.
!
Because the Children function returns a set, it appears in the Set group of
the Syntax Example list.
MDX includes the following other function that returns sets similar to the
Children function:
!
The Siblings function returns all the members that share a parent with the
specified member.
You can find more information about this function by searching on the function
name in Microsoft SQL Server Books Online.
Topic Objective
To explain the syntax and
results of the Children
function.
Lead-in
The Children function
returns members that share
a common parent.
Example
Delivery Tip
Because students have
already been exposed to the
Children function in the
previous group activity, treat

this topic as a review—that
is, do not spend a lot of
time.
Ask why Children returns a
set whereas Parent returns
a member. Because the
hierarchy, by definition, gets
larger as you move down.
Related Functions
Delivery Tip
These related functions are
included for reference only.
Do not spend any time
explaining them.
Module 6: Creating and Manipulating Sets 11


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Single-Level Descendants Function
!
Returns a Set of Members at a Specific Level or
Distance
!
Is Similar to the Ancestor Function, but Moves Down
!
Returns Descendants at All Levels If You Omit Level
!
Appears in the Set Group of the Syntax Example List
Descendants([1998],[Calendar Month])

Descendants([1998],[Calendar Month])
Returns the set of all months in 1998
Returns the set of all months in 1998
Descendants([Bread])
Descendants([Bread])
Returns all descendants of Bread,
at all levels
Returns all descendants of Bread,
at all levels


The Ancestor function returns a single member at a specific level, higher in the
hierarchy tree. The Descendants function, in turn, returns a set of members.
Descendants(«Member»,[«Level»])
The following example returns the set of all months in 1998.
Descendants([1998], [Calendar Month])

The following example returns all the descendants of Bread, at all levels of the
hierarchy.
Descendants([Bread])

When you use the Descendants function, consider the following facts and
guidelines:
!
The most common form of the Descendants function returns the members
of a level that are descendants of a specified member. In place of a level,
you can give a numeric value that specifies the distance—that is, the number
of levels between the specified member and the resulting members.
!
The Descendants function is analogous to the Ancestor function: you give

it a starting member and a level name or distance number. The only
difference is that the Ancestor function moves up, and the Descendants
function moves down.
!
If you omit the level argument from the Descendants function, it returns all
the members that descend from the specified member, without regard to the
level. In effect, you get the subtree with the specified member as the top
member.
!
Because the Descendants function returns a set of members, it appears in
the Set group of the Syntax Example list.

Topic Objective
To describe how the
Descendants function can
be used to return a set of
members at one level.
Lead-in
The Descendants function
is similar to the Ancestor
function.
Syntax
Example 1
Example 2
Delivery Tip
Because students have
already been exposed to the
Descendants function in
the previous group activity,
treat this topic as a review—

that is, do not spend a lot of
time.
Ask why Descendants
returns a set whereas
Ancestor returns a
member. Because the
hierarchy, by definition, gets
larger as you move down.
12 Module 6: Creating and Manipulating Sets


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Leaf-Level Descendants Function
!
Optional Third Argument Adds Flags
!
LEAVES Flag Returns Only Descendants at Leaf-Level
Descendants([Maya Gutierrez], , LEAVES))
Descendants([Maya Gutierrez], , LEAVES))
Returns leaf-level descendants of Maya at
any level
Returns leaf-level descendants of Maya at
any level


The Descendants function can also return a set that consists only of leaf-level
members. This is particularly useful with a parent-child dimension, where the
leaf-level members may occur on different levels.
To return a set that includes only leaf-level members, you use an optional third

argument to specify the levels from which you want to return the descendants.
Descendants(«Member», [«Level»],LEAVES)
The following example returns all the employees who report—directly or
indirectly—to Maya Gutierrez.
Descendants ([Maya Gutierrez], , LEAVES))


MDX includes the following other functions that return sets similar to the
Descendants function:
!
The Descendants function has additional optional arguments that allow you
to return various subsets of the descendants of a member.
!
The Ancestors function returns the set of ancestors between a specified
member and a specified level—or the top of the tree—with one member
from each level.
You can find more information about these functions by searching on the
function name in Microsoft SQL Server Books Online.
Topic Objective
To describe how the
Descendants function can
be used to return the leaf-
level members under a
specified member.
Lead-in
The Descendants function
can also be used to return a
set of members that are all
leaf-level members.
Syntax

Example
Related Functions
Delivery Tip
Because students have
already been exposed to the
Descendants function in
the previous group activity,
treat this topic as a review—
that is, do not spend a lot of
time.
Delivery Tip
These related functions are
included for reference only.
Do not spend any time
explaining them.
Module 6: Creating and Manipulating Sets 13


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Lab A: Using Set Creation Functions


Objectives
After completing this lab, you will be able to:
!
Create sets by using the Members and Descendants functions.

Prerequisites
Before working on this lab, you must have successfully completed modules 1

through 5 in course 2093A, Implementing Business Logic with MDX in
Microsoft SQL Server 2000.
Estimated time to complete this lab: 15 minutes

Topic Objective
To introduce the lab.
Lead-in
In this lab, you will create
sets by using the Members
and Descendants
functions.
Explain the lab objectives.
14 Module 6: Creating and Manipulating Sets


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

Exercise 1
Using Set Creation Functions
In this exercise, you will use functions that retrieve a set from a dimension—the
Members function and the Descendants function.
As you complete each procedure, compare the result as shown in the procedure
screen shot to the result on your own computer. If there is a difference, recheck
your entry and refer back to the related group activity procedures as necessary.
If you still cannot reconcile your result, then refer to the answer file, which is
located in:
C:\MOC\2093A\Labfiles\L06\Answers.
You can copy and paste expressions from this file into the query pane for any
given procedure.
Before beginning the exercises in this lab, verify that the following objects exist

in Analysis Manager:
!
The Market database
!
The Sales cube

If these objects do not exist in Analysis Manager, you must perform the
following procedure before you continue with this lab.
!
To restore the Market database
1. In the left pane of Analysis Manager, expand the Microsoft Analysis
Services folder.
2. Right-click the Server icon, and then click Restore Database.
3. Navigate to the C:\Moc\2093A\Batches folder.
4. Select Market.cab, click Open, and then click Restore.

Delivery Tip
The procedures in this
exercise essentially
replicate the previous group
activities but without the
answers.

Students having difficulty
with the procedures should
first refer back to the group
activity procedures and then
go to the answer file for
guidance.
Module 6: Creating and Manipulating Sets 15



BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

!
To show all the members of a dimension
In this procedure, you use the Members function to generate a report that
includes all members of the Employee dimension. MembersDimension.txt in
the Answer folder is the completed MDX expression used in this procedure.
1. In Windows Explorer, navigate to C:\MOC\2093A\LabFiles, double-click
MDX2093A.exe, and then click OK to connect to the server.
2. When asked to open a query file, navigate to the folder
C:\MOC\2093A\LabFiles\L06, and double-click the file LabA.mdx.
1. In the DB list, select Market, and then in the Cube list, select Sales.
2. Modify the initial MDX statement to create a report that shows Sales
Dollars and Sales Units across the Columns axis and all the members of the
Employee dimension down the Rows axis.
What MDX query statement did you use?
SELECT
{[Sales Dollars], [Sales Units]} ON COLUMNS,
Employee.Members ON ROWS
FROM Sales
____________________________________________________________
____________________________________________________________
____________________________________________________________

3. Click the Run Query button , and then verify that the Results pane, which is
located in the lower left corner of the MDX Builder, appears similar to the
following table.



16 Module 6: Creating and Manipulating Sets


BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

!
To show the children of a member
In this procedure, you use the Children function to create a set that consists of
members that are the children of a specified member. MemberChildren.txt in
the Answer folder is the completed MDX expression used in this procedure.
1. With the LabA.mdx file open in the MDX2093A sample application, in the
Queries list, select Children of a Member.
2. Modify the initial MDX statement to create a report that shows Sales
Dollars and Sales Units across the Columns axis and all the children of
Meat down the Rows axis.
What MDX query statement did you use?
SELECT
{[Sales Dollars], [Sales Units]} ON COLUMNS,
Meat.Children ON ROWS
FROM Sales
____________________________________________________________
____________________________________________________________
____________________________________________________________

3. Run the query, and then verify that the Results pane appears similar to the
following table.


Module 6: Creating and Manipulating Sets 17



BETA MATERIALS FOR MICROSOFT CERTIFIED TRAINER PREPARATION PURPOSES ONLY

!
To show single-level descendants of a member
In this procedure, you use the Descendants function to generate a report that
displays a set of members from a single level that share a common ancestor.
MembersDescendantsLevel.txt in the Answer folder is the completed MDX
expression used in this procedure.
1. With the LabA.mdx file open in the MDX2093A sample application, in the
Queries list, click Descendants on a Level.
2. Modify the initial MDX statement to create a report that shows Sales
Dollars and Sales Units across the Columns axis and all the Meat products
down the Rows axis.
What MDX query statement did you use?
SELECT
{[Sales Dollars], [Sales Units]} ON COLUMNS,
Descendants([Meat],[Product Name]) ON ROWS
FROM Sales
____________________________________________________________
____________________________________________________________
____________________________________________________________
3. Run the query, and then verify that the first few rows of the Results pane
appear similar to the following table.


×