Module 5 Creating
Module 5 Creating
Contents
Overview 1
Understanding MDX Query Statements 2
Creating Simple MDX Query Statements 15
Lab A: Creating Simple MDX Query
Statements 32
Review 38
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.
Microsoft, Excel, Office, PowerPoint, and SQL Server are either registered trademarks or
trademarks of Microsoft Corporation in the U.S.A. and/or other countries.
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.
Instructor Notes
Presentation: In this module, students will learn how to create simple multidimensional
60 Minutes expression (MDX) query statements that generate a report. Students will learn
the terminology that is used to create a query, and then they will be introduced
Lab: to an interface that can be used to process a query and create a report. Finally,
15 Minutes students will learn about different types of simple query statements and how to
create them.
At the end of this module, students will be able to:
! Understand MDX query statement terminology.
! Write simple MDX query statements by using the MDX2093A application.
Required Materials
To teach this module, you need the following materials:
! Microsoft® PowerPoint® file 2093A_05ppt
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 demonstration.
! Complete the labs.
! Review the Teacher Preparation materials on the Teacher Preparation
compact disc.
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.
Other Activities
Difficult Questions
Following are difficult questions that students might 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. Sometimes the WHERE clause is called a Filter axis. If it is an axis, why
can’t you put a set on it?
The WHERE clause is sometimes called an axis, but that is technically
incorrect. The technical term for the Filter clause is slicer specification.
2. What is the difference between a slicer, a filter, and the WHERE clause?
They can all be terms for the same thing. The tuple from the WHERE
clause is called a slicer specification in the Analysis Services
documentation, but the same thing is called Filter area in the Microsoft
Office PivotTable® list control, and Page area in a Microsoft Excel
PivotTable report.
3. If I will never write a custom client application, why should I create MDX
statements?
You might never use MDX to create a report, but many complex
calculated members require aggregations over multiple values. To
create those calculations, you must be familiar with sets. Creating MDX
query statements is the best way to learn how to work with sets.
4. Do all the tuples in a set have to come from the same dimension?
If each tuple contains only one member, then all the members must
come from the same dimension. If the tuples in a set contain two
members, then all the tuples must have two members, with the first
member of each tuple coming from one dimension and the second
member of each tuple coming from a different dimension.
5. When would you create a report using more than two axes?
For a printed, tabular report, you will invariably use only two axes—
row and column. Most client applications, however, will allow you to
place multiple nested dimensions on either the Row or Column axis. In
a charting application, you might have three or more axes represented.
6. When would you use the range operator in a set?
MDX has a large number of functions that return sets—many of which
allow you to manipulate other sets. Those functions, which will be
introduced in Module 6, are simpler and less likely to create an error
than the range operator. You might want to create a set by using the
range operator when testing a particular set of members.
7. A query with only one axis must have a Columns axis. What if you want
only one axis, but want it to appear on as rows?
The terms Columns and Rows are simply aliases for the underlying axis
names—Axis(0) and Axis(1). A client application can display the
Columns axis on the rows of a report.
Module Strategy
Major sections of this module begin with or include a group activity followed
by a review lecture and then a lab. 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 can
present a new MDX function by showing first its construction and then its
result set as an actual calculated member formula or in 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 results being tested.
! Students follow along
In some cases, you might 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 can also refer to answer files
that are available for each procedure within 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 completing the labs.
! Answer files for group activities
Where applicable, answer files are provided for each procedure in a group
activity. If necessary to facilitate your demonstration, copy and paste the
correct expression from the answer file into the Calculated Member Builder.
Overview
Topic Objective
To provide an overview of
the module topics and
objectives. ! Understanding MDX Query Statements
Lead-in ! Creating Simple MDX Query Statements
In this module, you will learn
how to create query
statements by using MDX.
This section introduces the basic terminology and concepts of an MDX query
Delivery Tip statement.
Briefly explain the bullets on
this diamond slide to provide The following topics are included in this section:
context for the upcoming
group activity where the ! MDX Expressions versus MDX Query Statements
items are functionally
demonstrated. This topic reviews the difference between MDX expressions and MDX
query statements.
! Values: Discrete and Aggregated
This topic introduces why it is important to learn how to create an MDX
query statement, even if your ultimate purpose is to create calculated
members.
! The Function of an MDX Query Statement
This topic explains that the function of an MDX query is to extract values
from an online analytical processing (OLAP) cube and put them into a cell
set, or report.
! Group Activity: Using MDX Terms in a Report
The group activity uses the Microsoft® Office PivotTable® list browser
control to introduce MDX terminology.
! MDX Terms
This topic reviews the important terms used in an MDX query statement.
MDX has two major functions: creating expressions and creating query
Delivery Tip statements.
This slide is for review and
reorientation. You have
already covered MDX MDX Expression
expressions in preceding Creating expressions is one of the major tasks for MDX:
modules, and now you are
moving on to MDX query ! An MDX expression is a multidimensional formula.
statements. Do not spend
much time on this slide. ! MDX expressions are essentially analogous to formulas in a spreadsheet.
You use MDX expressions to create calculated members.
Set of Members
Multiple Values
You know how to create
MDX expressions that use
discrete value (Tuple) (Tuple)
(Tuple) (Tuple)
Result Result
Aggregated Values
The single value needed by a calculated member can come from a large number
of values aggregated together. For example, to calculate a year-to-date value,
you must add the values for all the months leading up to the current month.
Rather than specify each month individually, you specify which set of months
you want to retrieve the values from.
Calculated members that use aggregated values are very useful. To create them
effectively, you must first understand how to create sets of members. The best
way to learn how to work with sets of members is to create MDX query
statements.
Even if you never intend to create a custom application or to use an MDX query
statement, learning how to create them will be extremely useful as you create
sophisticated calculated members that require dynamically aggregated values.
MDX Drama
Action
1,299,343
1,943,244
2,299,419
1,905,510
Query Romance 906,045 720,358
Comedy 1,358,210 2,020,358
Report
A report is the output that the user sees. It is based on data from the cube. It has
the following characteristics:
! A report does not have dimensions; it has axes—typically, a Rows axis and
a Columns axis. An axis can include members from more than one
dimension.
! A report can be asymmetrical. That is, a report contains only selected values
from selected levels of selected dimensions from the cube. For example, in a
report, you can display all the states under USA, but none of the states under
Canada or Mexico.
! A report can have a slicer specification. A report typically displays only a
small fraction of the cells in a cube.
An MDX query statement consists of the instructions for extracting a report
from a cube.
In this group activity, you can follow along on your own computer with your
instructor or observe the demonstration.
You will learn how to use MDX terminology in the context of a report in the
Office PivotTable list browser control. Browsers such as the Office PivotTable
list use MDX query statements to populate a report.
The terminology you will learn includes:
! Default members of a dimension
! The Filter clause tuple overriding default members
! Sets on an axis
! Selecting individual members for a set
! Selecting all the members of a level or dimension
! Putting multiple dimensions on one axis
Ask what member is used The initial report in the Explore.htm file shows only a single cell that
for each dimension—the shows the total value for the Sales Units measure. This grand total is a
default member. single value from the cube. To retrieve this value, Microsoft SQL Server™
2000 Analysis Services requires a tuple.
Note Because the Time Fiscal and Time Calendar dimensions are
hierarchies of the same dimension, you can include only one in the report at
a time. However, the report still uses the default member of the unused
hierarchy.
Ask how useful a report with
a single member would be. The default member allows a query to ignore some of the dimensions in a
cube, because if a dimension does not appear in the slicer specification, it
Ask students what they always uses the default member.
might want on the report—
for example, more than one If a dimension does appear in the slicer specification, it can use either the
member from a dimension default member or a different member. Putting a dimension in the slicer
on the rows and columns specification of a report overrides the default member for that dimension.
axes of a report.
2. Click the arrow next to the Product dimension list, select Meat, and then
click OK. Now only the total for meat shows.
The current report has dimension members only in the slicer specification,
which creates a report displaying only a single value.
Note According to Microsoft SQL Server 2000 Books Online, the term for the
tuple that overrides the default tuple is slicer specification. In the Microsoft
Office PivotTable list, the term for the slicer specification is Filter area. In the
Microsoft Excel PivotTable report, the term for the slicer specification is Page
field. The terms slicer, Filter, and Page are essentially synonyms.
The three countries—plus the total—appear. The Rows axis now displays a
set that contains four positions. Each position in the set corresponds to a
member from the State dimension.
2. Click the Country level label, and click the Expand toolbar button.
Ask how many positions are The regions appear. Even though the labels are split into two columns—to
now in the set on the Rows show the levels of the dimension—each position in the set still contains only
axis—eight. a single member from the State dimension.
Notice that the State and Region columns show all the members from the
respective levels. In other words, you did not put these members on the axis
by adding individual members; you added all the members of the level at
one time.
Ask how many positions are The Columns axis displays a set.
in the set—three. Ask which
You individually select members from the Measures dimension. You add or
dimension each member
came from—the Measures
remove them one at a time. This is different from the way that you typically
dimension. add members to a non-measures dimension such as State. You can,
however, remove individual members from a set on an axis.
4. To restore the members you removed, click the drop-down arrow on the
Country button. Select the Show All check box, and click OK.
With a non-measures dimension, you add all the members of the level, and
then remove members one at a time by using the drop-down list. With the
Measures dimension, you add members one at a time.
In essence, you can create a set in any of the three following ways:
• Display all the members from a level.
• Include only explicit members—typically the Measures dimension.
• Exclude explicit members from the members on a level.
The report now shows both categories and countries on the Rows axis. The
Rows axis still contains a single set—a set with 13 positions—but each
position in the set now contains a two-member tuple—a coordinate from
more than one dimension.
Technically, a set always contains tuples. Even when there is only one
dimension on an axis, the set consists of single-member tuples.
The report now shows countries, categories, and calendar years on the Rows
axis.
The blank rows for 1997 and 1999 appear. In an MDX query, you can
choose whether to display empty rows. In the PivotTable list, the default is
not to display them.
4. Close Internet Explorer.
Summary
Each position in a set consists of a tuple—typically a partial tuple. A partial
tuple is a way to specify coordinates from more than one dimension on a single
axis.
Again, contrast the slicer specification with the Rows and Columns axes:
! The Rows and Columns axes can contain a set—a set of tuples.
! The slicer specification can contain only a single tuple—the same as a
single position in a set on one of the other axes.
For each value in the report, there is a single member from each dimension that
contributed to the complete coordinate for that cell in the cube. The member for
a dimension can come from any of the axes, and more than one dimension can
be represented on a single axis. Any dimension not found on the Columns axis,
Rows axis, or slicer specification uses the default member.
MDX Terms
Topic Objective
To review MDX terms.
Lead-in
Let’s review the terms
! Axis – The Row and Column Headings of a Report
commonly used in MDX ! Set – Multiple Members on an Axis
query statements.
! Slicer – The Filter Specification for a Report
! Tuple – One Member from Each Dimension Defined by
Slicer Specification and Row/Column Sets
! Member – A Single Item from a Dimension
An MDX query statement shares some terms with a standard MDX expression
Delivery Tip and has some additional terms.
Because students have
already been exposed to the ! Axis
basic MDX terms in the
previous group activity, treat A report typically has two axes, one for rows and one for columns. The axes
this topic as a review—that are the mechanism for dicing values in a report—as is frequently used in the
is, do not spend a lot of term slicing and dicing to describe OLAP user interface elements and
time. analysis methods.
! Set
A set is one or more members of a dimension. A set appears on the Rows or
Columns axis of a report.
! Slicer
The slicer specification for a report appears above the report in a PivotTable
list. The slicer specification contains only a single tuple—typically a partial
tuple. This is the mechanism for slicing values in a report—as is frequently
used in the term slicing and dicing to describe OLAP user interface
elements and analysis methods.
! Tuple
Each value retrieved from a cube must have a complete tuple. The slicer
specification can contain a partial tuple that contributes to the complete
tuple for a cell. The sets on the Rows and Columns axes contain partial
tuples that also contribute to the complete tuple for each cell.
! Member
A member is a single item from a dimension. A tuple consists of one
member from one or more dimensions. A set consists of one or more tuples.
A specific member for each dimension is necessary to retrieve a value from
a cube.
In this group activity, you can follow along on your own computer with your
instructor or observe the demonstration
You will learn the interface to the MDX2093A application.
Tip If the Results pane does not appear, click the Split View button to the
right of the Run Query button to redisplay the Results pane below the
Metadata pane.
3. In the toolbar DB list, select Market as the database name. Then, at the top
of the Metadata pane, click Sales as the cube name.
After you select a cube, the Data list—the leftmost section of the Metadata
pane—displays the cube name as the top-level parent, plus the names of all
the dimensions in the cube. The Data list in the Metadata pane is essentially
equivalent to the Data list in the Calculated Member Builder. The Syntax
Examples list is essentially equivalent to the Functions list in the Calculated
Member Builder.
The MDX2093A application interface consists of three vertical panes:
! The toolbar
The toolbar allows you to create and save a new query file. It also allows
you to create and select new queries in the query file. A query file has the
extension MDX, but it is a simple text file that you can view by using
Microsoft Notepad or any simple text editor.
Caution The MDX2093A application will not allow you to save a query
file until you have created at least one query. Be sure to use the Save As
command on the File menu when you first save the file. Until you have
saved the file and given it a name, the Save toolbar button does nothing.
To use the Data list in the Metadata pane, you must select a cube from the
Cube list. Selecting the cube has no effect on the query, but it determines
the metadata you can view. To avoid confusion, be sure to select the cube
you will be using as the source for your queries.
! The Results pane
This is where you view the results.
Toolbar buttons allow you to control which panes are currently displayed.
Often, the most useful option is to display all three panes together.
In this group activity, you can follow along on your own computer with your
instructor or observe the demonstration
You will learn how to create simple MDX queries.
The single number that appears in the report—35,696.00—is the total Sales
Units for the entire cube. This is the original number from the Office
PivotTable list control in the Explore.htm file. The query uses the default
member from each dimension because the query does not specify a member
from any dimension.
Note Instead of using two sequential slash marks (//) to comment the
remainder of the line, you can use two sequential hyphens (--) for the same
purpose. If you want to create a comment that is either a partial line or spans
multiple lines, begin the comment with a slash mark followed by an asterisk
(/*) and end it with an asterisk followed by a slash mark (*/).
2. Click the Save Query File button on the toolbar, type Queries as the name
of the file, and then click OK.
You can add multiple queries to this single file, but you cannot save a file
until you have entered something in the Query pane.
Ask students which group to 1. Click the New Query button. On the Query menu, point at Insert
use—the Set group. Hint: Template, and click Columns Only.
You must put a Set on an 2. Click in the «Cube» token, and then in the Data list, double-click Sales.
axis.
3. Click in the «Set» token. Then expand the Set group, and double-click the
Members - Level function.
Ask students: 4. Click in the «Level» token. In the Data list, expand the Product dimension,
and double-click the Category level node in the Product dimension. The
What you should use to final query should look like this:
replace the «Level» token—
a level. SELECT
[Product].[Category].Members ON COLUMNS
Where you can find one—in FROM Sales
the Data list
5. To view the results of the query, click the Run Query button.
The labels from the Subcategory level appear as column headings in the
report.
6. Save the query file.
The tokens in the function templates help you know what kind of item to
add to a specific location of the query. For example, you must replace the
«Level» token with the name of a level.
The following are the three most common types of tokens:
• The tokens «Set» and «Tuple» are MDX constructs that do not exist in
the OLAP database. Therefore, you typically replace them with
functions from the appropriate groups.
• The «Cube», «Dimension», «Hierarchy», and «Level» tokens all refer to
OLAP objects. Therefore, you typically replace these tokens with items
from the metadata tree.
• The «Member» token is the place where MDX and the cube meet. You
can replace the «Member» token either with a constant member from the
metadata tree or with a function from the Member group.
Each axis has a set of members, and the members in each set come from a
level.
Note The terms Columns and Rows are simply aliases for the true names of
the axes, Axis(0), and Axis(1), respectively. The underlying names make it
clearer to understand why a single-axis report must include a Columns axis
but not a Rows axis. Technically, an MDX query can have up to 128 axes,
with alias names for the first few. There are, however, essentially no
situations in which it is necessary to use more than two heading axes for a
report.
Note When you create a set without using a Set function, you need to
enclose the set in braces, even if it contains only a single member.
Note When you create a set using a set function, you do not need to
enclose the set in braces, but braces around a set are always acceptable.
When you create a set by using explicit members, you must enclose the set
in braces.
If the first tuple in a set consists of a single member, each subsequent tuple
in that set must be a member of the same dimension.
The labels do not change, but the values do. The slicer specification in the
WHERE clause does not appear on an axis.
The only thing that can go into a WHERE clause is a single tuple. As with
all tuples, if the tuple contains more than one member, it must be enclosed
in parentheses. If the tuple contains only a single member, it does not need
parentheses.
[Calendar
[Calendar Quarter].Members
Quarter].Members
Returns
ReturnsAll
AllMembers
Membersofofthe
theQuarters
Quarters
Level
Level of Time, RegardlessofofYear
of Time, Regardless Year
The most useful tool for creating a set of members is to retrieve all the members
from a level. The Level Members function returns the set of all members of a
level, without respect to any members higher or lower in the hierarchy.
Syntax «Level».Members
Example The following example returns all members of the Quarters level of the Time
dimension, regardless of year.
[Calendar Quarter].Members
Delivery Tip When you use the Level Members function, consider the following facts and
Because students have guidelines:
already been exposed to the
Level Members function in ! The Level Members function does essentially what the Office PivotTable
the previous group activity, list does—when you drag a level to the report, all the members of the level
treat this topic as a review— appear.
that is, do not spend a lot of
! For the level argument, you can use any item in the metadata tree that is
time.
preceded by a level—that is, clustered dot—icon.
! You can use the Level Members function on a Rows or Columns axis—for
example,[Calendar Quarter].Members ON COLUMNS.The Level
Members function appears in the Set group of the Syntax Examples list.
{{ {{ [Sales
[Sales Dollars]
Dollars] }} ,, {{ [Meats]
[Meats] }} }}
{{ [All
[All Product],
Product], [Product].[Category].Members
[Product].[Category].Members }}
You can create sets that include explicit members. This is what the Office
PivotTable list control does when you add measures to a report.
Example 1 In an MDX query statement, you include explicit member names inside braces.
The braces convert the members into a set. For example:
{ [Sales Dollars] , [Cost Dollars] }
Delivery Tip
Because students have
already been exposed to
Because each element of a set is actually a tuple, you can enclose each of the
using sets to return explicit member names in parentheses. If the tuple includes members from only a single
members in the previous dimension, the parentheses are not necessary.
group activity, treat this topic
as a review—that is, do not
If you want to put a single member on an axis, you must put braces around the
spend a lot of time. member, because a set is the only thing that can go on an axis.
Example 2 You can place extra brackets around any set to create a set of sets, which is still
a set. You combine two sets by putting a pair of brackets around them. For
example:
{ { [Sales Dollars] } , { [Meats] } }
Example 3 You can use braces to add an individual member, such as a total, to a set of all
the members of a level. For example:
{ [All Product], Catgory.Members }
Note You can also specify a range of members by using a colon, much as
when creating a range in Microsoft Excel. For example, {[Bread]:[Meat]}
returns a set containing all the members between Bread and Meat, inclusive.
The beginning and ending members of a range must be on the same level of the
same dimension. This notation is used only infrequently, because there are
usually set functions that can create the desired result. When using the range
operator, you must still enclose the members in braces.
Sets work with axes in an MDX query. When using sets and axes, consider the
Delivery Tip following facts and guidelines:
Because students have
already been exposed to ! If you want to want to display multiple members from a single dimension in
how sets work with axes in a report, you must put the members into a set and place the set on an axis
the previous group activity,
treat this topic as a review— ! A set is a collection of one or more tuples. Each tuple may contain a
that is, do not spend a lot of member from only one dimension, in which case the set appears to be a
time. collection of one or more members of a dimension, but, technically, the set
always contains tuples.
! A set appears only on an axis. You must never put a set in the slicer
specification—that is, in a WHERE clause. The slicer specification requires
a tuple.
! Each axis must include a set. You cannot have an axis without a set, and
each axis contains one and only one set.
! You cannot skip an axis—that is, if there is a Rows axis, there must be a
Columns axis, but the order of axes does not matter.
! A dimension can appear only one time on the axes and the WHERE clause.
If you include the same dimension on more than one axis, the dimension
would appear in more than one in a tuple, which would then be an invalid
coordinate.
! An MDX query statement can have as many as 128 axes, a fraction of the
65,535 dimensions of a cube, but far more than you could ever use.
! The official name for each axis consists of the word Axis followed by the
axis number in parentheses. The first axis is numbered zero. The term
Columns is equivalent to Axis(0). The term Rows is equivalent to Axis(1).
SELECT
SELECT FROM
FROM Sales
Sales
Returns
Returnssingle
singlevalue
valueusing
usingdefault
default
member
memberofofeach
eachdimension
dimension
A simple query consists of only a single cell—the result of a single tuple. The
simplest possible query consists of only the keywords SELECT and FROM,
along with the name of the cube.
This selects a single value by using the default member of each dimension.
Syntax SELECT FROM «Cube»
This returns a report that contains a single value. The tuple for the value
Delivery Tip consists of the default member of each dimension.
Because students have
already been exposed to the
simplest query in the Note You can add a comment to an MDX statement simply by entering two
previous group activity, treat adjacent slash marks (//). MDX ignores everything from that point to the end of
this topic as a review—that that line. You can also add a comment by entering two adjacent hyphens (--).
is, do not spend a lot of Again, MDX ignores everything from the hyphens to the end of the line. To
time. control the beginning and ending point of a comment, use a slash mark
followed by an asterisk (/*) to begin the comment, and an asterisk followed by
a slash mark (*/) to end the comment.
WHERE Clause
Topic Objective
To describe the use of a
WHERE clause.
Lead-in ! Acts As a Slicer Specification
A WHERE clause is ! Uses a Tuple
equivalent to the slicer
specification of a PivotTable ! Overrides the Default Member
list report.
SELECT
SELECT FROM
FROM Sales
Sales
WHERE ([Bread],[1998])
WHERE ([Bread],[1998]) Returns
Returnssingle
singlevalue
valueusing
usingBread
Breadfor
for
1998
1998with
withdefault
defaultmember
memberforforother
other
dimensions
dimensions
Example SELECT
FROM Sales
WHERE ([Bread], [1998])
This query statement returns a report containing a single value, with Bread for
Delivery Tip the Product dimension, 1998 for the Time.Calendar dimension, and the
Because students have
already been exposed to the
default member from all remaining dimensions.
WHERE clause in the When using a WHERE clause, consider the following facts and guidelines:
previous group activity, treat
this topic as a review—that ! The WHERE clause accepts a tuple—with one or more dimensions
is, do not spend a lot of represented.
time.
! In the context of the query statement, the WHERE clause overrides the
default member for each dimension represented in the tuple.
SELECT
SELECT
{[Sales
{[Sales Dollars],
Dollars], [Sales
[Sales Units]
Units] ON
ON Columns,
Columns,
Product.Category.Members
Product.Category.Members ON Rows
ON Rows
FROM
FROM Sales
Sales
Returns
Returnsreport
reportwith
withtwo
twocolumns
columnsand
and
one
one row for each productcategory
row for each product category
To display multiple values in a query, you must put members into a set on an
axis. A typical query contains two axes: Columns and Rows.
Syntax SELECT
«Set» ON COLUMNS,
«Set» ON ROWS
FROM «Cube»
WHERE «Tuple»
Example SELECT
{[Sales Dollars], [Sales Units] ON COLUMNS,
Product.Category.Members ON ROWS
FROM Sales
This query statement returns a report with two columns—one for Sales Dollars
Delivery Tip and one for Sales Units. The report has one row for each member of the
Because students have
already been exposed to the
Category level of the Product dimension.
queries with axes in the The Rows and Columns axes definitions follow the SELECT keyword, and a
previous group activity, treat
comma separates the axes.
this topic as a review—that
is, do not spend a lot of
time.
Objectives
Explain the lab objectives. After completing this lab, you will be able to:
! Create simple MDX query statements.
Prerequisites
Before working on this lab, you must have successfully completed modules 1
through 4 in course 2093A Implementing Business Logic with MDX in
Microsoft® SQL Server™ 2000.
Exercise 1
Creating Simple MDX Query Statements
In this exercise, you will create simple queries by putting sets on axes, using the
Delivery Tip Level Members function, and creating sets by using explicit members.
The procedures in this
exercise essentially As you complete each procedure, compare the result as shown in the procedure
replicate the previous group screen shot to the result on your own computer. If there is a difference, recheck
activities, but without the
your entry and refer back to the related group activity procedures as necessary.
answers.
If you still cannot reconcile your result, then refer to the answer file in which is
located in the following folder: C:\MOC\2093A\Labfiles\L05\Answers.
You can copy and paste expressions from this file into the MDX2093A
application for any given procedure.
Before beginning the exercises in this lab, verify that the following objects exist
in Analysis Manager:
! The Market database
! The Basic Sales virtual cube
If these objects do not exist in Analysis Manager, you must perform the
following procedure before you continue with this lab.
3. Run the query. If the comment is entered correctly, you do not get an error
message. Verify that the Results pane content is similar to the following:
____________________________________________________________
2. Run the query. Verify that the Results pane content is similar to the
following:
____________________________________________________________
2. Run the query. Verify that the Results pane content is similar to the
following:
____________________________________________________________
2. Run the query. Verify that the Results pane content is similar to the
following:
____________________________________________________________
2. Run the query. Verify that the Results pane content is similar to the
following:
Review
Topic Objective
To reinforce module
objectives by reviewing key
points. ! Understanding MDX Query Statements
Lead-in ! Creating Simple MDX Query Statements
The review questions cover
some of the key concepts
taught in the module.
1. What are some of the differences between a cube and an MDX report?
A cube has dimension, whereas a report has axes—and multiple
dimensions can appear on one axis.
A cube contains all possible values at all aggregation levels, whereas a
report is a small selection of values.
3. To retrieve a value from a cell in the cube requires a complete tuple. What
are the three sources for providing members for that complete tuple?
The default member of a dimension.
The tuple in the WHERE clause.
The tuples in the sets on the axes.
4. What is the simplest possible MDX query statement for retrieving a value
from a cube named Finance?
SELECT FROM Finance.
5. What is the keyword that begins the slicer specification, and what can you
put in a slicer specification?
WHERE is the keyword, and you can put only a tuple in the slicer
specification.
6. What can you put on an axis? Can you put a single member on an axis?
A set. You can put a member on an axis as long as you put braces
around it to turn it into a set.
7. Can you have a Rows axis without a Columns axis? Can you have a Rows
axis before a Columns axis?
No. Yes.