MDX Essentials : MDX Operators: The Basics - Page 3January 28, 2003 CommasDiscussion:The comma operator separates tuples forming a set, particularly when we find it difficult to practically define a set using a range of component members (more on ranges later). SyntaxAs we have seen in the above examples, as well as in previous examples in the series, MDX uses the comma operator to separate tuples, which define a slice of data from a cube. (Tuples are composed of an ordered collection of one member from each of one or more dimensions) PracticeWe can see, through the following example, as well as in most of the examples in this lesson, the role of the comma operator in building a set. The example below constructs a relatively tedious row in order to contrast the process with that of the operator that we discuss next. Let's say that we have been asked to generate several measures for the California warehouse group by management for purposes of evaluating aggregate performance of the warehouses over the 1997 / 1998 measurement periods. These seven measures, used as critical success factors for the California warehouse group manager, are as follows:
We will assemble the required information by taking the following steps: 1. Select File -> New from the top menu in the Sample Application. 2. Type the following query into the Query pane: -- MDX03-3: Tutorial Query No. 3
SELECT
{[Measures].[Store Invoice],[Measures].[Supply Time],
[Measures].[Warehouse Cost],[Measures].[Warehouse Sales],
[Measures].[Units Shipped],[Measures].[Units Ordered],
[Measures].[Warehouse Profit]} ON COLUMNS,
{ [Time].[1997], [Time].[1998] } ON ROWS
FROM Warehouse
WHERE
([Warehouse].[All Warehouses].[USA].[CA])
3. Click the green Run Query button to execute the query. The query delivers the results that were requested by the management for the California warehouse group manager's performance appraisal. Illustration 5: The Query Results, Showing the Desired Measures 4. Save the query as MDX03-3. We will now examine another operator, the colon, and another way to achieve our results from the above query but with a little less typing. ColonsDiscussion:The colon operator provides us a means of leveraging the natural order of members to create a set. Order is important, because the levels within a dimension house their respective members either in member name or member key order. We can take advantage of the order of the members, and define sets based upon ranges within the order, by using the colon operator. When we use the colon operator to define a set, members on both sides of the colon operator are included in the resulting set. The fact that the range selection is inclusive is a key concept. SyntaxWe can illustrate the syntax within which a colon operator is used with the following example, excerpted from our practice exercise in the immediately preceding section. The set of members specified in the set: {[Measures].[Store Invoice],[Measures].[Supply Time], [Measures].[Warehouse Cost],
[Measures].[Warehouse Sales],[Measures].[Units Shipped],
[Measures].[Units Ordered],[Measures].[Warehouse Profit]}
can be retrieved with the following syntax: { [Measures].[Store Invoice]: [Measures].[Warehouse Profit]}
provided that the range specified by the colon takes into account the natural order of the members. Let's verify this point by putting it into action in the following exercise. PracticeWe can readily see the value of the colon operator in the following example, where we can use a colon to mitigate the tedium of listing the members individually and separating them by commas, as we did in the previous example. With the exception of applying the colon's "range logic" to the specification, the query and its result set are identical to that of the last exercise. 1. Select File -> New from the top menu in the Sample Application. 2. Type the following query into the Query pane: -- MDX03-4: Tutorial Query No. 4
SELECT
{ [Measures].[Store Invoice]: [Measures].[Warehouse Profit]} ON COLUMNS,
{ [Time].[1997], [Time].[1998] } ON ROWS
FROM Warehouse
WHERE
([Warehouse].[All Warehouses].[USA].[CA])
3. Click the green Run Query button to execute the query. As we can see above, the end members of the range of tuples that form the set defining the columns in the query are separated by the colon operator. We observe the results, which appear in the Query pane as soon as Analysis Services fills the cells that it determines to be specified by the query. The requested measures should appear as shown in Illustration 6 below. Illustration 6: The Query Results, after Leveraging the Economies of the Colon Operator The more new query delivers the same results obtained before, and provides the measures that were requested by management, with more compact syntax. 4. Save the query by as MDX03-4. As we move into the next lessons' coverage of many of the functions available in MDX, as well as into progressively more advanced stages of query building, we will call upon the basic operators frequently. A grasp of the basic operators and functions will be vital to success in our taking advantage of the more complex MDX concepts that we will uncover. Practice with these components will assure that their use comes as second nature, and will create a foundation from which the elegance and power of MDX can be fully exploited. Next in Our Series ...In this article, we introduced additional ways to construct and manipulate tuples and sets, reviewing some of the most basic components involved. The operators we explored in this lesson included curled braces "{}", commas "," and colons ";". For each of these, we discussed the role it plays in MDX expressions and queries, the syntax involved in putting it into action, and the practical use of the operator in helping us to achieve our objectives. In our next lesson, MDX Operators and Functions: The .Members Function, we will introduce a powerful function that allows us to retrieve and perform operations upon levels, hierarchies and dimensions. The .Members function lies at the core of numerous related functions, and provides what will be shown as a useful basis for many of the operations that we will undertake with MDX as a tool.
Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum. MDX Essentials Series
The LEVEL_NUMBER Member Property
The LEVEL_UNIQUE_NAME Intrinsic Member Property Intrinsic Member Properties: The HIERARCHY_UNIQUE_NAME Property Intrinsic Member Properties: The DIMENSION_UNIQUE_NAME Property Further Combination of BottomCount() with Other MDX Functions Combine BottomCount() with Other MDX Functions to Add Sophistication Basic Set Functions: The BottomCount() Function, Part I Intrinsic Member Properties: The MEMBER_VALUE Property Intrinsic Member Properties: The MEMBER_UNIQUE_NAME Property Intrinsic Member Properties: The MEMBER_NAME Property Intrinsic Member Properties: The MEMBER_KEY Property Intrinsic Member Properties: The MEMBER_CAPTION Property Set Functions: The StripCalculatedMembers() Function Set Functions: The AddCalculatedMembers() Function MDX Numeric Functions: The Min() Function MDX Numeric Functions: The Max() Function Set Functions: The .AllMembers Function MDX Essentials: Set Functions: The MeasureGroupMeasures() Function String Functions: The .Properties Function, Part II String Functions: The .Properties Function Logical Functions: IsGeneration(): Conditional Logic within Filter Expressions MDX Scripting Statements: Introducing the Simple CASE Statement Logical Functions: IsGeneration(): Conditional Logic within Calculations Logical Functions: IsAncestor(): Conditional Logic within Filter Expressions MDX Clauses and Keywords: Use HAVING to Filter an Axis Logical Functions: IsAncestor(): Conditional Logic within Calculations Logical Functions: IsSibling(): Conditional Logic within Filter Expressions Logical Functions: IsSibling(): Conditional Logic within Calculations MDX Operators: The IsLeaf() Operator: Conditional Logic within Filter Expressions MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations MDX Numeric Functions: The .Ordinal Function Other MDX Entities: Perspectives MDX Operators: The IS Operator MDX Set Functions: The Distinct() Function MDX Set Functions: The ToggleDrillState() Function Set Functions: The DrillUpLevel() Function Set Functions: The DrillDownLevelTop() and DrillDownLevelBottom() Functions MDX Set Functions: DrillDownLevel() MDX Set Functions: The DRILLUPMEMBER() Function MDX Essentials: Set Functions: The DRILLDOWNMEMBERTOP() and DRILLDOWNMEMBERBOTTOM() Functions MDX Essentials : Set Functions: The DRILLDOWNMEMBER() Function MDX Essentials: Drilling Through with MDX: The DRILLTHROUGH Statement MDX Essentials: String Functions: The .UniqueName Function MDX Essentials: String Functions: The .Name Function MDX Essentials: String / Numeric Functions: The CoalesceEmpty() Function MDX Essentials: Basic Set Functions: The TopCount() Function, Part II MDX Essentials: Basic Set Functions: The TopCount() Function, Part I MDX Essentials: Enhancing CROSSJOIN() with Calculated Members MDX Essentials: Set and String Functions: The GENERATE() Function MDX Essentials: The CROSSJOIN() Function: Breaking Bottlenecks MDX Essentials: String / Numeric Functions: More on the IIF() Function MDX Essentials: String / Numeric Functions: Introducing the IIF() Function MDX Essentials: Logical Functions: The IsEmpty() Function MDX Essentials: Basic Set Functions: The EXTRACT() Function MDX Essentials: Numeric Functions: Introduction to the AVG() Function MDX Essentials: Basic Member Functions: The .Item() Function MDX Essentials: Basic Set Functions: Subset Functions: The Subset() Function MDX Essentials: Basic Set Functions: Subset Functions: The Tail() Function MDX Essentials: Basic Set Functions: Subset Functions: The Head() Function MDX Essentials: Basic Set Functions: The CrossJoin() Function MDX Essentials: Basic Numeric Functions: The Count() Function MDX Essentials: Basic Set Functions: The Filter() Function MDX Essentials: Basic Set Functions: The EXCEPT() Function MDX Essentials: Basic Set Functions: The Intersect() Function MDX Essentials: Basic Set Functions: The Union() Function MDX Essentials: Basic Set Functions: The Order() Function MDX Essentials - MDX Time Series Functions, Part III: The LastPeriods() and ParallelPeriod() Functions MDX Time Series Functions, Part II: The OpeningPeriod () and ClosingPeriod() Functions MDX Essentials - MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions MDX Essentials: MDX Member Functions: "Relative" Member Functions MDX Member Functions: The Cousin () Function MDX Essentials: Member Functions: More "Family" Functions MDX Member Functions: The "Family" Functions MDX Essentials: MDX Members: Introducing Members and Member MDX Essentials : MDX Operators: The Basics MDX Essentials: Structure of the MDX Data Model MDX at First Glance: Introduction to SQL Server MDX Essentials |