Home > SQL Server Tips > Data Warehousing and Business Intelligence > Sub-queries supported in Analysis Services MDX
SQL Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DATA WAREHOUSING AND BUSINESS INTELLIGENCE

Sub-queries supported in Analysis Services MDX


By Baya Pavliashvili
03.13.2007
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


MDX in SQL Server 2005 Analysis Services brings exciting improvements including query support and expression/calculation language. Baya Pavliashvili highlights CASE, statements, sub-queries and SCOPE functions, which make MDX more powerful and flexible for your intricate business intelligence solutions.

MDX now supports sub-queries, allowing you to change the criteria of the outer query dynamically, depending on the context returned by the sub-query. Each MDX query is executed with a context of a multi-dimensional space (sometimes referred to as a sub-cube). If a query doesn't include a sub-query, then the context is the entire cube. For example, let's suppose we wanted to reduce the previous query to only return the calculations related to the first quarter of fiscal year 2001. We can alter the query as follows:


Note that the sub-query is included in the FROM clause, as opposed to Transact-SQL where a sub-query would typically be part of the WHERE clause. As expected, the results will be limited to the first quarter of fiscal year 2001:

Reseller Sales AmountGrowth in reseller sales amount Growth in reseller sales amount IIF
Jul-01$489,328.58(null)(null)
Aug-01$1,538,408.31214.39%214.39%
Sep-01$1,165,897.08-24.21%-24.21%
Oct-01$844,721.00-27.55%-27.55%
Nov-01$2,324,135.80175.14%175.14%
Dec-01$1,702,944.54-26.73%-26.73%

This example is simplistic. Of course we could just as easily include the DESCENDANTS function in the original query to limit the result set. However, sub-queries can come in extremely handy if you have a complicated WHERE clause that contains multiple members. This is important because, although MDX allows sets in the WHERE clause (another welcomed improvement in Analysis Services 2005), it only allows one member from each hierarchy. For example, we could modify the following query to limit the output to only the sales occurring in Australia and Canada:


The output would look like this:

Reseller Sales AmountGrowth in reseller sales amount Growth in reseller sales amount IIF
Jul-01$115,360.90 (null)(null)
Aug-01$316,981.07174.77%174.77%
Sep-01$205,640.87-35.13%-35.13%
Oct-01$234,907.2514.23%14.23%
Nov-01$381,806.4862.53%62.53%
Dec-01$258,662.88-32.25%-32.25%

In previous versions of Analysis Services, the only way to accomplish similar functionality would be to create a named set and use AGGREGATE function. Unfortunately, AGGREGATE function had many limitations, not the least of which was its performance.



More powerful Analysis Services MDX in SQL Server 2005

 Home: Introduction
 Part 1: CASE statements now supported by MDX script
 Part 2: Sub-queries supported in Analysis Services MDX
 Part 3: MDX functions: SCOPE, THIS and FREEZE

ABOUT THE AUTHOR:   
Baya Pavliashvili is a DBA manager overseeing database operations that support more than one million users. Pavliashvili's primary areas of expertise are performance tuning, replication and data warehousing.
Copyright 2007 TechTarget

More on this topic:

  • Use cube partitions to improve Analysis Services performance
  • Analysis Services 2005 in SQL Server has improved security
  • SQL Server Business Intelligence toolbox


    Rate this Tip
    To rate tips, you must be a member of SearchSQLServer.com.
    Register now to start rating these tips. Log in if you are already a member.


    Submit a Tip




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


    RELATED CONTENT
    SQL Server data warehousing/business intelligence
    Utilize SSAS for data predictions and classification using Excel
    Tutorial: SQL Server Integration Services (SSIS) best practices
    FAQ: Troubleshooting SQL Server Reporting Services
    What's new in SQL Server 2008 Reporting Services?
    SQL Server 2008 Integration Services delivers new features
    Tips for tuning SQL Server 2005 to improve reporting performance
    Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
    Troubleshoot Web service issues in SQL Server 2005 Reporting Services
    Ordering the results of a SQL query
    Using MDX and UDM in a SQL Server Analysis Services environment

    SQL Server 2005 (Yukon)
    SQL Server Service Broker Tutorial and Reference Guide
    Tips for tuning SQL Server 2005 to improve reporting performance
    Using DATEADD and DATEDIFF to calculate SQL Server datetime values
    SQL Server consolidation: Why it's an optimization technique
    Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
    Using SQL Server datetime functions GETDATE, DATENAME and DATEPART
    SSIS error message due to installation problem on SQL Server 2005
    SQL Server data conversions from date/time values to character types
    Basics for working with DATETIME and SMALLDATETIME in SQL Server 2005
    How to configure Database Mail in SQL Server 2005 to send mail
    SQL Server 2005 (Yukon) Research

    SQL Server Development
    Change tempdb from 'C' drive
    Tempdb changes in SQL Server 2005
    MDX functions: SCOPE, THIS and FREEZE
    More powerful Analysis Services MDX in SQL Server 2005
    CASE statements now supported by MDX script
    Top 5 SQL Server query tips
    Update table rows in SQL Server 2000
    Delete .bak files automatically with CLR
    Stored procedure overview in SQL Server
    Syntax error in SQL Server script
    SQL Server Development Research

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    data aggregation  (SearchSQLServer.com)
    data preprocessing  (SearchSQLServer.com)
    data warehouse  (SearchSQLServer.com)
    FileMaker  (SearchSQLServer.com)
    GIS  (SearchSQLServer.com)
    MOLAP  (SearchSQLServer.com)
    pivot table  (SearchSQLServer.com)
    Quiz: SQL Server 2000  (SearchSQLServer.com)
    SQL  (SearchSQLServer.com)
    T-SQL  (SearchSQLServer.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • SQL Server Development - .NET, C#, T-SQL, Visual Basic
    HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts