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
Introduction to SQL Server 2000 Analysis Services: Handling Time Dimensions
Introduction to SQL Server 2000 Analysis Services: Working with Dimensions
Introduction to SQL Server 2000 Analysis Services: Creating Our First Cube

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

Justtechjobs.com Post A Job | Post A Resume

Featured Database Articles

MS SQL

January 10, 2005

Introduction to MSSQL Server 2000 Analysis Services: Distinct Count Basics: Two Perspectives

By William Pearson

Rendering Distinct Counts Using MDX

We now have a set of "answers" that we can attempt to replicate in direct MDX. Let's initialize the MDX Sample Application, as a platform from which to perform our practice exercises, taking the following steps:

1.     Start the MDX Sample Application.

We are initially greeted by the Connect dialog, shown in Illustration 14.

Click for larger image

Illustration 14: The Connect Dialog for the MDX Sample Application

The illustration above depicts the name of my server, MOTHER1, and properly indicates that we will be connecting via the MSOLAP provider (the default).

2.  Click OK.

The MDX Sample Application window appears.

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.

5.  Click File --> New to open a blank Query pane.

The MDX Sample Application window should resemble that depicted in Illustration 15, complete with the information from the Warehouse cube displaying in the Metadata tree (left section of the Metadata pane).


Illustration 15: The MDX Sample Application Window (Compressed View)

We will begin creating our query with a focus on returning results in the same general formation as the Data View we left in the Cube Editor. We will retrieve the Warehouse Profit and Product Count measures, as pictured in Illustration 13 above. Next, we will attempt to add a calculated measure that we craft directly in MDX, to replicate the distinct count information we obtained with the Product Count measure that we created in Analysis Manager earlier. This will afford us a side-by-side comparison between our "MDX solution" and the "Analysis Manager" approach we took in the last section.

1.  Create the following new query:


-- ANSYS31-1 Initial Attempt at Distinction
WITH MEMBER 
   [MEASURES].[ProdCount] 
AS  
   'DISTINCTCOUNT({[Product].MEMBERS})'
SELECT
   { [MEASURES].[Warehouse Profit], [MEASURES].[Product Count],
[MEASURES].[ProdCount] } ON COLUMNS,
   {[Product].CHILDREN} ON ROWS
FROM 
   [Warehouse]

The above represents an attempt to meet the information consumers' objectives - with what appears to be the straightforward use of the DISTINCTCOUNT() function. This might seem intuitive to a practitioner who has given up on the handful of non-working or nebulous examples that can be found on the web, (and which happen to be about all we seem to have as a basis for learning MDX, in many instances). While this approach ultimately fails to provide the desired solution, as we shall see, it should not be surprising that we might attempt this, given the definition in the Books Online, not to mention the words used in the name of the function itself. (Most will agree, also, that it is better to attempt it now, than when under the gun of an employer or a hurried client.)

The calculated member ProdCount embodies the function. I named it ProdCount to distinguish if from Product Count, the measure we created while within the user interface in the earlier section, which I have also decided to present within the results dataset for comparison purposes. Warehouse Profit is also presented to align with our Data View as we left it in the last section.

2.  Execute the query using the Run Query button.

The results dataset appears as shown in Illustration 16.


Illustration 16: The Results Dataset - DISTINCTCOUNT() Approach

3.  Save the query as ANSYS31-1.

It doesn't require a huge leap of logic to conclude that the ProdCount calculated measure is generating a transaction count. The count is correctly "distinct," within its own (actual) meaning, but not at all what the information consumers have requested in our practice example.

Having seen why the "intuitive" approach is lacking, let's resort to another, more cumbersome approach, which results in the distinct product values that we seek.

4.  Create the following new query:


-- ANSYS31-2  Distinction at its Finest 
WITH MEMBER
   [MEASURES].[CalcCount]
AS
   'COUNT(CROSSJOIN({[MEASURES].[Warehouse Profit]}, DESCENDANTS
    ([Product].CURRENTMEMBER, [Product].[Product Name])), EXCLUDEEMPTY)'
SELECT 
   {[MEASURES]. [Warehouse Profit], [MEASURES].[Product Count], [MEASURES].[CalcCount] } 
      ON COLUMNS,
   [Product].CHILDREN ON ROWS
FROM
   [Warehouse]

The above "attempt at distinction" is embodied by the calculated measure CalcCount, named, again, simply as a means of distinguishing it from the measure we created in the Cube Editor, and which we include once again for comparison purposes.

The above approach may not have been the initial impulse that many of us had in tackling what seemed to be a straightforward replication of the Data View we saw earlier. What we are doing, in short, with the CrossJoin() function is marrying the Warehouse Profit values with the products, and returning (thanks to EXCLUDEEMPTY) a count of the non-empty pairings. The Descendants() function builds in flexibility, allowing us to apply the logic equally well to a group of products as to the full set of products. The key to this is the selection of the current member's descendents, adding the "relativity" that so pointedly underscores the power of the .CurrentMember function.

5.  Execute the query using the Run Query button.

The results dataset appears as shown in Illustration 17.


Illustration 17: The Results Dataset - Distinction Attained

6.  Save the query as ANSYS31-2.

The values for the new measure are in alignment with those of the measure we created in the Cube Editor. (All that remains to make the measures identical is the addition of formatting syntax).

7.  Exit the MDX Sample Application and Analysis Manager when ready.

Conclusion

In this article, we introduced the concept of distinct counts, discussing why they are often a requirement in our multidimensional analysis efforts, and those of the information consumers whom we support. In our introduction and overview, and throughout our examination of the objects and MDX syntax we explored to achieve our illustrative ends, we highlighted some of the challenges that are inherent in distinct counts.

We performed practice exercises, to illustrate solutions for hypothetical business needs that called upon the use of a distinct count capability, obtaining exposure to the options afforded us by the MSAS user interface, as well the MDX syntax involved with using the alternative solutions that we proposed.

We now have a basis in distinct counts that will allow us to examine more detailed nuances surrounding the capability. In subsequent articles, we will examine specific performance considerations inherent in the production of distinct counts, as well as options that are available to tune our efforts for more efficient operation. The need for distinct counts is a fact of business life, and mastery of the costs and results of this vital capability represent a unique opportunity to add another tool to our MSAS skill sets.

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

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

Introduction to MSSQL Server Analysis Services Series
Part 88: Introduction to Security in Analysis Services
Part 87: Cube Storage: Planning Partitions from a SQL Server Management Studio Perspective
Part 86: Cube Storage: Planning Partitions (Business Intelligence Development Studio Perspective)
Part 85: Cube Storage: Introduction to Partitions
Part 84: Introduction to Cube Storage
Part 83: Attribute Discretization: Customize Grouping Names
Part 82: Attribute Discretization: Using the “Clusters” Method
Part 81: Attribute Discretization: Using the “Equal Areas” Method
Part 80: Attribute Discretization: Using the Automatic Method
Part 79: Introduction to Attribute Discretization
Part 78: More Exposure to Settings and Properties in Analysis Services Attribute Relationships
Part 77: Attribute Relationships: Settings and Properties
Part 76: Introduction to Attribute Relationships in MSSQL Server Analysis Services
Part 75: Attribute Member Values in Analysis Services
Part 74: MSSQL Analysis Services - Attribute Member Names
Part 73: Attribute Member Keys – Pt 2: Composite Keys
Part 72: Attribute Member Keys – Pt 1: Introduction and Simple Keys
Part 71: Dimension Attributes: Introduction and Overview, Part V
Part 70: Dimension Attributes: Introduction and Overview, Part IV
Part 69: Dimension Attributes: Introduction and Overview, Part III
Part 68: Dimension Attributes: Introduction and Overview, Part II
Part 67: Dimension Attributes: Introduction and Overview, Part I
Part 66: Dimensional Model Components: Dimensions Part II
Part 65: Dimensional Model Components: Dimensions Part I
Part 64: Manage Unknown Members in Analysis Services 2005, Part II
Part 63: Manage Unknown Members in Analysis Services 2005, Part I
Part 62: Alternatively Sorting Attribute Members in Analysis Services 2005
Part 61: Introduction to Linked Objects in Analysis Services 2005
Part 60: Distinct Counts in Analysis Services 2005
Part 59: Positing the Intelligence: Conditional Formatting in the Analysis Services Layer
Part 58: Administration and Optimization: SQL Server Profiler for Analysis Services Queries
Part 57: Mastering Enterprise BI: Time Intelligence Pt. II
Part 56: Mastering Enterprise BI: Time Intelligence Pt. I
Part 55: Design and Documentation: Introducing the Visio 2007 PivotDiagram
Part 54: Actions in Analysis Services 2005: The URL Action
Part 53: Actions in Analysis Services 2005: The Drillthrough Action
Part 52: Mastering Enterprise BI: Introducing Actions in Analysis Services 2005
Part 51: Mastering Enterprise BI: Introduction to Translations
Part 50: Mastering Enterprise BI: Introduction to Perspectives
Part 49: Introduction to the Analysis Services 2005 Query Log
Part 48: Mastering Enterprise BI: Working with Measure Groups
Part 47: Mastering Enterprise BI: Introduction to Key Performance Indicators
Part 46: Mastering Enterprise BI: Extend the Data Source with Named Calculations, Pt. II
Part 45: Mastering Enterprise BI: Extend the Data Source with Named Calculations, Pt. I
Part 44: Process Analysis Services Objects with Integration Services
Part 43: Usage-Based Optimization in Analysis Services 2005
Part 42: Named Sets Revisited
Part 41: Migrating an Analysis Services 2000 Database to Analysis Services 2005
Part 40: Introducing Data Source Views
Part 39: Reporting Options for Analysis Services Cubes: MS Excel 2003 and More ...
Part 38: Mastering Enterprise BI: Create Aging "Buckets" in a Cube
Part 37: Mastering Enterprise BI: Relative Time Periods in an Analysis Services Cube, Part II
Part 36: Mastering Enterprise BI: Relative Time Periods in an Analysis Services Cube
Part 35: Process Analysis Services Cubes with DTS
Part 34: Presentation Nuances: CrossTab View - Same Dimension
Part 33: Point-and-Click Cube Schema Simplification
Part 32: Manage Distinct Count with a Virtual Cube
Part 31: Distinct Count Basics: Two Perspectives
Part 30: Semi-Additive Measures and Periodic Balances
Part 29: Performing Incremental Cube Updates - An Introduction
Part 28: Partitioning a Cube in Analysis Services - An Introduction
Part 27: Basic Storage Design
Part 26: Derived Measures vs. Calculated Measures
Part 25: Creating a Dynamic Default Member
Part 24: Another Approach to Local Cube Design and Creation
Part 23: Introduction to Local Cubes
Part 22: Actions in Virtual Cubes
Part 21: Putting Actions to Work in Regular Cubes
Part 20: Reporting Options for Analysis Services Cubes: ProClarity Part II
Part 19: Reporting Options for Analysis Services Cubes: ProClarity Professional, Part I
Part 18: Using Calculated Cells in Analysis Services , Part II
Part 17: Using Calculated Cells in Analysis Services, Part I
Part 16: MSAS Administration and Optimization: Toward More Sophisticated Analysis
Part 15: MSAS Administration and Optimization: Simple Cube Usage Analysis
Part 14: Build a Web Site Traffic Analysis Cube: Part II
Part 13: Build a Web Site Traffic Analysis Cube: Part I
Part 12: Reporting Options for Analysis Services Cubes: Cognos PowerPlay
Part 11: Reporting Options for Analysis Services Cubes: MS FrontPage 2002
Part 10: Reporting Options for Analysis Services Cubes: MS Excel 2002
Part 9: Drilling Through to Details: From Two Perspectives
Part 8: Custom Cubes: Financial Reporting - Part II
Part 7: Custom Cubes: Financial Reporting
Part 6: Exploring Virtual Cubes
Part 5: Working with the Cube Editor
Part 4: Parent-Child Dimensions
Part 3: Handling Time Dimensions
Part 2: Working with Dimensions
Part 1: Creating Our First Cube


Go to page: Prev  1  2  3  4  5  

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
Inner and outer select mussab 2 March 10th, 04:16 AM
SQL server 2008 in windows 7 pro problem theresatan 2 March 6th, 08:35 PM
code for re-build index and shrink db or file? mib 7 March 5th, 08:50 AM
sql maintenance plan fails database missing tbrownch 3 February 24th, 08:53 AM









The Network for Technology Professionals

Search:

About Internet.com

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