Free Newsletters:
DatabaseDaily  
Database Journal
Search Database Journal:
 
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum DBA Videos
internet.com

» Database Journal Home
» DBA Videos
» Database Articles
» Database Tutorials
MS SQL
Oracle
MS Access
MySQL
DB2
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» DBA Jobs
» Sitemap

News Via RSS Feed



follow us on Twitter

Marketplace Partners
Be a Marketplace Partner

internet.commerce
Be a Commerce Partner


















Mariposa Bot Shipped With Vodafone Smartphone

IT Job Market Heating Up: Report

Bing Makes Strides But Momentum Stalls

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Database Journal | DBA Support | SQLCourse | SQLCourse2







Related Articles
Basic Set Functions: The BottomCount() Function, Part I
MDX Essentials: Basic Set Functions: Subset Functions: The Tail() Function

Senior Systems Administrator – Windows (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

Featured Database Articles

MS SQL

November 21, 2008

Combine BottomCount() with Other MDX Functions to Add Sophistication

By William Pearson

As we might have expected, this simple beginning hardly achieves our ultimate objectives: it returns the bottom four Cities from the perspective of total Reseller Sales Amount for CY 2003 – but the bottom four from the entire Adventure Works organization. (The bottom four performers happen to have had no Reseller Sales – therefore the “nulls” we see in the Reseller Sales Amount column.) We will next advance beyond the initial, basic query above, where we employ another MDX function, Descendants(), to supply the «Set» argument for the BottomCount() function; we have a bit more to do to reach our goal of presenting the bottom performer Cities by U.S. State.

NOTE: For information surrounding the Descendants() function, see my article MDX Member Functions: The "Family" Functions, a member of the MDX Essentials series at Database Journal. For an introduction to the .CurrentMember function, see MDX Member Functions: "Relative" Member Functions, another article in the same monthly column.

3.  Select File > Save As, name the file MDX072-1-1, and place it in a meaningful location.

4.  Leave the query open for the next section.

Next, we need to add logic to generate the same “bottom four” data, but for an ancestor of City (another level in the Geography hierarchy of the Geography dimension), the State that the City inhabits. To do so, we will introduce more MDX functions, as we see in the next step.

5.  Within the query we have saved as MDX072-1-1, replace the top comment lines of the query with the following:

-- MDX072-1-2, BottomCount(), combined with Ancestor()  
--   and .Name in a calculated member, to provide  
--   U. S. States with each of "Bottom 4 Least Performing    
--   (with regard to Total Reseller Sales Amounts) Cities 
--   in Adventure Works Organization in CY 2003"

6.  Save the query as MDX072-1-2, to keep MDX072-1-1 intact as a working sample.

7.  Add the following lines to the query, between the top comment line we just replaced, and the SELECT keyword that begins the query:

WITH 
MEMBER
   [Measures].[State] 
AS
   'ANCESTOR([Geography].[Geography].CURRENTMEMBER,     
      [Geography].[Geography].[State-Province]).NAME'

This will create the calculated member State, which will allow us to present the States alongside their respective member Cities.

NOTE: For an introduction to the Ancestor() function, see my article MDX Member Functions: The "Family" Functions, another member of the MDX Essentials series at Database Journal.

8.  Modify the ON AXIS(0) line of the query, which already contains the Reseller Sales Amount measure, to contain the new State calculated member we defined above, as follows:

{[Measures].[State], [Measures].[Reseller Sales Amount]} ON AXIS(0),

9.  Leave the remainder of the query in its original state.

The Query pane appears as depicted in Illustration 3, with our modifications marked.


Illustration 3: The Query with Added Calculated Member and Axis(0) Specification Modification

10.  Execute the query by clicking the Execute (!) button in the toolbar.

The Results pane is populated, and the dataset shown in Illustration 4 appears.


Illustration 4: Results Dataset – After Our Query Modifications

We note that the State to which each of the “bottom four” Cities (still the bottom four for the entire Adventure Works organization, we also note) belongs appears in the results. Our calculated member has taken us a step closer to realization of the information consumers’ requirements.

11.  Re-save the file as MDX072-1-2.

12.  Leave the query open for the next step.

At this point, all that remains is to generate the “bottom four” data for each of the U.S. States, limiting the States to the U.S. States within which Adventure Works reseller sales occur. The word “generate” is particularly apt here: we will use the Generate() function in our efforts to return the “bottom four” from each of the U.S. States involved.

13.  Within the query we have saved as MDX072-1-2, replace the top comment line of the query with the following:

-- MDX072-1-3, Addition of Generate() to retrieve 
--   4 Worst Performing Cities in Each U. S. State (with regard to 
--      total Reseller Sales Amounts) in CY 2003"

14.  Save the query as MDX072-1-3, to keep MDX072-1-2 intact as a working sample.

15.  Substitute the following for the entire existing ON AXIS(1) specification within the SELECT statement of the query:

{GENERATE
    (
       [Geography].[Geography].[Country].[United States].CHILDREN,
           BOTTOMCOUNT(
              DESCENDANTS(
                 [Geography].[Geography].CURRENTMEMBER,
                     [Geography].[Geography].[City]   
                        ),
                     4,
                 [Measures].[Reseller Sales Amount])
              )
           }
        ON AXIS(1)

(In actuality, we are only adding the Generate() statement to the “front end” of the ON AXIS(1) specification, as it already existed from earlier steps, with a closing right parenthesis - “)” - just before the ON AXIS keyword).

The Generate() statement builds a set based upon the bottom performing Cities, as retrieved by the BottomCount() function (with Reseller Sales Amount as the <<Numeric Expression>> argument, and the Descendants() function, once again, specifying the «Set» argument as the individual Cities), limited to U.S. States (the “children” of the United States level of the Geography dimension / Geography hierarchy.

NOTE: For information surrounding the Generate() function, see my MDX Essentials article Set and String Functions: The GENERATE() Function, (where we perform a combination of Generate() and BottomCount(), as well). For an introduction to the .Children function, see MDX Member Functions: The "Family" Functions, within the same series.

16.  Leave the remainder of the query in its original state.

The Query pane appears as depicted in Illustration 5, with our additions marked.


Illustration 5: The Query with Substituted Comments and New ON AXIS(1) Specification

17.  Execute the query by clicking the Execute (!) button in the toolbar.

The Results pane is populated, and the dataset partially shown in Illustration 6 appears.


Illustration 6: Results Dataset (Partial View) – After Final Modifications

Finally, we see the presentation as requested by the information consumers: CY 2003 total Reseller Sales Amounts for the four Cities with the lowest Reseller Sales Amounts - for each of the U. S. States within which Adventure Works has conducted Reseller Sales operations. We note that several Cities display “nulls” – this is appropriate in our simple example where, for instance, two of the four least performing” Cities in the State of Alabama appear in our dataset because they had no Reseller Sales activity, over the Calendar Year by which we have sliced within our query. (There are other ways we can refine the query for presentation purposes – say to show the “least four” Cities with non-zero values, etc., - but such refinements are beyond the scope of this article.)

18.  Re-save the file as MDX072-1-3.

19.  Select File -> Exit to leave the SQL Server Management Studio, when ready.

Summary ...

This article served as an extension of our previous introductory article, Basic Set Functions: The BottomCount() Function. We briefly reviewed the operation of the BottomCount() function, and then extended our examination of BottomCount() to include a somewhat more sophisticated use.

We defined an illustrative business need, as posed to us by hypothetical groups of information consumers, and, after discussing the need in general, with regard to challenges inherent to meeting them with the BottomCount() function in particular. We then constructed, in a step-by-step manner, a final query to meet the expressed requirements using a combination of BottomCount() and other MDX functions we have explored in articles of the MDX Essentials series. Throughout our practice example, we discussed the syntax contained within the solutions we constructed for the information consumers, as well as the datasets we obtained in employing BottomCount() and other functions, together with other surrounding considerations.

About the MDX Essentials Series ...

This article is a member of the MDX Essentials series, a monthly column designed to provide hands-on application of the fundamentals of the Multidimensional Expressions (MDX) language, with each article progressively adding features designed to meet specific real-world needs.

For more information about the column in general, as well as the software and systems requirements for getting the most out of the lessons included, please see my first article, MDX at First Glance: Introduction to MDX Essentials, among others.

» 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
Part 77: The LEVEL_NUMBER Member Property
Part 76: The LEVEL_UNIQUE_NAME Intrinsic Member Property
Part 75: Intrinsic Member Properties: The HIERARCHY_UNIQUE_NAME Property
Part 74: Intrinsic Member Properties: The DIMENSION_UNIQUE_NAME Property
Part 73: Further Combination of BottomCount() with Other MDX Functions
Part 72: Combine BottomCount() with Other MDX Functions to Add Sophistication
Part 71: Basic Set Functions: The BottomCount() Function, Part I
Part 70: Intrinsic Member Properties: The MEMBER_VALUE Property
Part 69: Intrinsic Member Properties: The MEMBER_UNIQUE_NAME Property
Part 68: Intrinsic Member Properties: The MEMBER_NAME Property
Part 67: Intrinsic Member Properties: The MEMBER_KEY Property
Part 66: Intrinsic Member Properties: The MEMBER_CAPTION Property
Part 65: Set Functions: The StripCalculatedMembers() Function
Part 64: Set Functions: The AddCalculatedMembers() Function
Part 63: MDX Numeric Functions: The Min() Function
Part 62: MDX Numeric Functions: The Max() Function
Part 61: Set Functions: The .AllMembers Function
Part 60: MDX Essentials: Set Functions: The MeasureGroupMeasures() Function
Part 59: String Functions: The .Properties Function, Part II
Part 58: String Functions: The .Properties Function
Part 57: Logical Functions: IsGeneration(): Conditional Logic within Filter Expressions
Part 56: MDX Scripting Statements: Introducing the Simple CASE Statement
Part 55: Logical Functions: IsGeneration(): Conditional Logic within Calculations
Part 54: Logical Functions: IsAncestor(): Conditional Logic within Filter Expressions
Part 53: MDX Clauses and Keywords: Use HAVING to Filter an Axis
Part 52: Logical Functions: IsAncestor(): Conditional Logic within Calculations
Part 51: Logical Functions: IsSibling(): Conditional Logic within Filter Expressions
Part 50: Logical Functions: IsSibling(): Conditional Logic within Calculations
Part 49: MDX Operators: The IsLeaf() Operator: Conditional Logic within Filter Expressions
Part 48: MDX Operators: The IsLeaf() Operator: Conditional Logic within Calculations
Part 47: MDX Numeric Functions: The .Ordinal Function
Part 46: Other MDX Entities: Perspectives
Part 45: MDX Operators: The IS Operator
Part 44: MDX Set Functions: The Distinct() Function
Part 43: MDX Set Functions: The ToggleDrillState() Function
Part 42: Set Functions: The DrillUpLevel() Function
Part 41: Set Functions: The DrillDownLevelTop() and DrillDownLevelBottom() Functions
Part 40: MDX Set Functions: DrillDownLevel()
Part 39: MDX Set Functions: The DRILLUPMEMBER() Function
Part 38: Set Functions: The DRILLDOWNMEMBERTOP() and DRILLDOWNMEMBERBOTTOM() Functions
Part 37: Set Functions: The DRILLDOWNMEMBER() Function
Part 36: Drilling Through with MDX: The DRILLTHROUGH Statement
Part 35: String Functions: The .UniqueName Function
Part 34: String Functions: The .Name Function
Part 33: String / Numeric Functions: The CoalesceEmpty() Function
Part 32: Basic Set Functions: The TopCount() Function, Part II
Part 31: Basic Set Functions: The TopCount() Function, Part I
Part 30: Enhancing CROSSJOIN() with Calculated Members
Part 29: Set and String Functions: The GENERATE() Function
Part 28: The CROSSJOIN() Function: Breaking Bottlenecks
Part 27: String / Numeric Functions: More on the IIF() Function
Part 26: String / Numeric Functions: Introducing the IIF() Function
Part 25: Logical Functions: The IsEmpty() Function
Part 24: Basic Set Functions: The EXTRACT() Function
Part 23: Numeric Functions: Introduction to the AVG() Function
Part 22: Basic Member Functions: The .Item() Function
Part 21: Basic Set Functions: Subset Functions: The Subset() Function
Part 20: Basic Set Functions: Subset Functions: The Tail() Function
Part 19: Basic Set Functions: Subset Functions: The Head() Function
Part 18: Basic Set Functions: The CrossJoin() Function
Part 17: Basic Numeric Functions: The Count() Function
Part 16: Basic Set Functions: The Filter() Function
Part 15: Basic Set Functions: The EXCEPT() Function
Part 14: Basic Set Functions: The Intersect() Function
Part 13: Basic Set Functions: The Union() Function
Part 12: Basic Set Functions: The Order() Function
Part 11: MDX Time Series Functions, Part III: The LastPeriods() and ParallelPeriod() Functions
Part 10: MDX Time Series Functions, Part II: The OpeningPeriod () and ClosingPeriod() Functions
Part 9: MDX Time Series Functions, Part I: PeriodsToDate() and Kindred Functions
Part 8: MDX Member Functions: "Relative" Member Functions
Part 7: MDX Member Functions: The Cousin () Function
Part 6: MDX Member Functions: More "Family" Functions
Part 5: MDX Member Functions: The "Family" Functions
Part 4: MDX Members: Introducing Members and Member
Part 3: MDX Operators: The Basics
Part 2: Structure of the MDX Data Model
Part 1: MDX at First Glance: Introduction to MDX Essentials


Go to page: Prev  1  2  

Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

MS SQL Archives








Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
shrinking a Database tkatende 2 March 19th, 08:55 AM
Dropping database yogesphu 3 March 19th, 08:52 AM
Inner and outer select mussab 3 March 17th, 11:05 AM
Help with Getting Started jozepeter 1 March 15th, 11:03 AM









The Network for Technology Professionals

Search:

About Internet.com

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