Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Jan 28, 2003

MDX Essentials : MDX Operators: The Basics - Page 3

By William Pearson

Commas

Discussion:

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

Syntax

As 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)

Practice

We 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:

  • Store Invoice
  • Supply Time
  • Warehouse Cost
  • Warehouse Sales
  • Units Shipped
  • Units Ordered
  • Warehouse Profit

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.

Colons

Discussion:

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.

Syntax

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

Practice

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


See All Articles by Columnist William E. Pearson, III


Discuss this article in the MSSQL Server 2000 Analysis Services and MDX Topics Forum.



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date