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 Mar 8, 2004

MDX Essentials: Basic Numeric Functions: The Count() Function - Page 4

By William Pearson


Excluding Empty Cells


The elimination of empty cells is a mere keyword away. We will accomplish our objective in the steps that follow:


1.  Within the query we have saved as MDX17-1, add the EXCLUDEEMPTY keyword to the Count() function, separated by a comma from the existing specified set, as shown:


'Count( {[Store Type].[Store Type].MEMBERS }, 
  EXCLUDEEMPTY)'

2.  Replace the top comment line of the query with the following:

-- MDX17-2:  Counting that excludes Empty Cells

The Query pane appears as shown in Illustration 4.

Click for larger image

Illustration 4: The Query with Modifications Circled

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

The Results pane is populated, and the dataset shown in Illustration 5 appears. We see that the counts drop to two, five and five, for the Canada, Mexico and USA Store Types, respectively.


Illustration 5: Result Dataset - Count() with EXCLUDEEMPTY Flag in Place

4.  Save the file as MDX17-2.

Let's tidy things up a bit by ordering our results dataset based upon the counts we have obtained.

5.  Within the query we have saved as MDX17-2, make the following change to the ON ROWS portion of the SELECT section of the query, as shown:

Change:

    { [Store].[Store Country].MEMBERS } ON ROWS

To:


{ORDER ( [Store].[Store Country].MEMBERS,
         [Store Type].[Types Count] , BDESC ) } ON ROWS

6.  Replace the top comment line of the query with the following:

    -- MDX17-3:  Ordering the Row Axis

The Query pane appears as shown in Illustration 6.


Illustration 6: The Query with Modifications Circled

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

The Results pane is populated, and the dataset shown in Illustration 7 appears. The results are ordered by Types Count, largest to smallest.


Illustration 7: Result Dataset - Ordered by Types Count (Descending)

NOTE: For a tutorial surrounding the Order() function, see MDX Essentials: Basic Set Functions: The Order() Function.

8.  Save the file as MDX17-3.

We appear to have attained our objective. One more step, near and dear to the hearts of those who wish to ensure the quality of their work, and particularly to recovering CPA's like myself, is a test of accuracy and completeness. Let's look at the answer we are about to give Finance from another perspective - and at the same time look ahead to the subject of our next lesson, the CrossJoin() function.



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