dcsimg

MDX Essentials: Basic Set Functions: The Order() Function - Page 3

October 13, 2003

Practice - Returning Hierarchized Data

Let's reinforce our understanding of the basics we have covered so far, and by using the Order() function in a manner that illustrates its operation in returning hierarchized data, one of the two general options that we have in order types. We will call upon the MDX Sample Application again, as our tool for constructing and executing the MDX we examine, and for viewing the result datasets we obtain.

1.  Start the MDX Sample Application.

2.  Clear the top area (the Query pane) of any queries or remnants that might appear.

3.  Ensure that FoodMart 2000 is selected as the database name in the DB box of the toolbar.

4.  Select the Warehouse cube in the Cube drop-down list box.

We will compose a simple query to gain an understanding of the use of the Order() function to return hierarchized data, or data sorted within hierarchical considerations. Our query will focus on Warehouse Cost, a value that is captured monthly within the FoodMart organization and which is stored in the Warehouse cube.

5.  Type the following query into the Query pane:

-- MDX12-1:  Tutorial Query No. 1
SELECT 
{[Measures].[Warehouse Cost]} ON COLUMNS,
{ ORDER({[Warehouse].[USA].[WA].Children, [Warehouse].[USA].[OR].Children},  
   ([Measures].[Warehouse Cost]) , DESC)}  ON ROWS
FROM Warehouse
WHERE ([Time].[Year].[1998])

Notice that the query we have input contains an Order() expression similar to the one we used in the previous section. The query also accomplishes a complementary objective: By selecting two separate state levels in the Warehouse dimension to populate the row axis in the query, we have constructed a scenario whereby we know that we have two separate hierarchical levels; we thus have a basis for confirming the real effects of using each of the hierarchical and nonhierarchical sort types.

6.  Execute the query by clicking the Run Query button in the toolbar.

Analysis Services populates the Results pane, presenting the dataset shown in Illustration 1.


Illustration 1: Result Dataset - Order() Expression in Place, Hierarchized, Descending

We see the total Warehouse Cost for the specified states returned for year 1998. The Order() function sorts our states (Washington and Oregon are specified in the query to populate the row axis) from "highest to lowest," (and thus "from Washington to Oregon"), respecting state groupings in those sorts. We obtain the seven Washington city-children, sorted highest to lowest, with respect to Warehouse Cost, followed by the two Oregon city-children, also sorted highest to lowest based upon Warehouse Cost in descending order.

7.  Select File -> Save As, and give the file a meaningful name and location, if it is desirable to save the query.

Practice - Returning Nonhierarchized Data

Let's take a look at the same operation with a "break hierarchy" sort type, BDESC, within an otherwise identical query. We will return to the MDX Sample Application, and perform the following steps:

1.  Clear the top area (the Query pane) of any queries or remnants that might appear.

2.  Ensure that FoodMart 2000 is selected as the database name in the DB box of the toolbar.

3.  Select the Warehouse cube in the Cube drop-down list box.

4.  Type the following query into the Query pane:

 -- MDX12-2:  Tutorial Query No. 2
 SELECT 
 {[Measures].[Warehouse Cost]
 } ON COLUMNS,
 { ORDER({[Warehouse].[USA].[WA].Children, [Warehouse].[USA].[OR].Children},  
 ([Measures].[Warehouse Cost]) , BDESC)}  ON ROWS
 FROM Warehouse
 WHERE ([Time].[Year].[1998])

Again, notice that the query we have input is identical to the last, with the exception of its use of the nonhierarchical BDESC sort type.

5.  Execute the query by clicking the Run Query button in the toolbar.

Analysis Services populates the Results pane, presenting the dataset shown in Illustration 2.


Illustration 2: Result Dataset - Order() Expression in Place, Nonhierarchized, Descending

We see the total Warehouse Cost for the specified states returned, once more, for year 1998. The Order() function sorts our Washington and Oregon warehouse city locations from highest to lowest, in terms of total Warehouse Cost, but this time the hierarchical level groupings are completely ignored. The warehouses cities are sorted solely with respect to Warehouse Cost. The Warehouse dimension's hierarchy, for purposes of our query, is "broken."

6.  Save the query as desired.

In conclusion, we can see that the Order() function provides flexible ways to arrange the display of our data, whether we wish to take hierarchies into consideration in our presentation or not.

Summary...

In this lesson, we explored the humble, yet versatile, Order() function. Order() finds itself an actor in many queries - queries that rank from the simplest to the most advanced. The Order() function provides the sorting capabilities we need within MDX, and is thus an important part of our analysis toolsets.

Through its support of hierarchies, MDX complicates sorting to a degree, as two general types of order, hierarchized and nonhierarchized, are possible. We explored how the Order() function stands ready to handle these scenarios, allowing us the options of arranging members within a given hierarchy, or of ignoring hierarchy completely in the arrangement of all members within the set we specify, and treating all to a simple sort. In addition to discussing the purpose of the Order() function, we examined of the syntax surrounding its use, and illustrated its application in practice exercises. Finally, we discussed the results we obtained in each exercise, remarking on the distinguishing characteristics of each.

» See All Articles by Columnist William E. Pearson, III

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








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers