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

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Rss Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles


Posted Feb 9, 2004

MDX Essentials: Basic Set Functions: The Filter() Function - Page 4

By William Pearson

Our modified query contains a Filter() function similar to the one we presented in the Remarks section above, but with a slight complication. The example not only demonstrates the operation of the function, but also accomplishes a complementary objective: It shows how we can easily compare the same measure under different dimensional scenarios - that is, in two different sets. In the current example, Units Shipped in two different quarters is compared by adding a Boolean expression as the search condition.

11.  Select File -> Save As, and name the query MDX16-2. Leave the query open, once again.

As we have already noted, the Filter() function can be used in conjunction with other functions to produce more complex results. Let's compound the business requirement we outlined earlier, and create an illustrative example of just such a case.

Let's say that the information consumers, while satisfied with the response we have supplied using the previous query, have been emboldened to ask for more. (This is probably a scenario well known to readers who act in a support capacity of this nature in the business world.) The consumers now state that they want to see the list of products that have experienced a decrease in shipping volume, as before, but this time they would like to see the products concerned within the context of the warehouses involved. In other words, they wish to see the products whose shipping volumes declined, grouped by the warehouses involved.

We can handle this easily with the introduction of a CrossJoin() function in our specification of the rows axis. To do so, we will take the following steps:

12.  Modify the ON ROWS specification of the query from the following:

    [Product].[Product Category].MEMBERS,
        (([Time].[1998].[Q1] , [Measures].[Units Shipped]) >
   ([Time].[1998].[Q2],[Measures].[Units Shipped])))} ON ROWS

to the following:

            [Product].[Product Category].MEMBERS),
                (([Time].[1998].[Q1] , [Measures].[Units Shipped]) >
                    ([Time].[1998].[Q2],[Measures].[Units Shipped])))} 
                        ON ROWS

The modified query appears in the Query pane as depicted in Illustration 4.

Illustration 4: The Query - CrossJoin() Added to Filter() Function

13.  Replace the existing comment line for the query with the following:

-- MDX16-3:  Tutorial Query No. 3

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

The filtered dataset is returned, as partially depicted shown in Illustration 5.

Illustration 3: Result Dataset - With CrossJoin() inside Filter() Function (Partial View)

Our modified query meets the objective established by the information consumers, and displays the products with declining shipping volumes over the Q1 and Q2 operating periods, by the warehouse location. We can thus see that, regardless of the "compound" nature of the set in our Filter() function, the results are returned with accuracy and completeness.

15.  Select File -> Save As, and name the query MDX16-3.

Many far more sophisticated uses for the Filter() function are possible, and, as we build our functional toolset within the MDX Essentials series in the months ahead, we will employ the function in numerous ways. It is often more efficient to ask for subset of a larger set than to specify each of the targeted set's member tuples.


In this lesson, we explored the powerful Filter() function, whose general purpose is to filter out parts of a set to return a precise subset to meet our needs. The Filter() function offers many flexible and innovative uses, and, as we have seen, can incorporate the operation of additional functions within its search condition to allow us to build substantial logic into our filtering efforts. The Filter() function is an excellent tool for the support of precise analysis.

In addition to discussing the purpose and operation of the Filter() function, we illustrated its application in a couple of practice exercises. We began with an unfiltered query, to which we then applied Filter(), to show its effectiveness in meeting a business need to return a subset of the initially unfiltered dataset. We then substituted a more complex Filter() function into our query to provide a solution within a second example, illustrating the way that we can combine other functions with a Filter() function to return more sophisticated datasets. Finally, throughout the creation and execution of the practice examples, we discussed the results we obtained to confirm our understanding of the function and its operation.

» 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

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