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 Business Intelligence (BI) and Data Warehousing
    DBA career paths could lead to business intelligence
    Are data warehouses made for the cloud?
    Q&A: Business intelligence gets a facelift in SQL Server 2008 R2
    Project Gemini gets a new name, Madison earns buzz
    Speed up reports in SQL Server Reporting Services with caching
    Data Transformation Services vs. SSIS: The key differences
    Using package configurations in SQL Server Integration Services (SSIS)
    How SQL Server 2008 components impact SharePoint implementations
    Achieving high availability and disaster recovery with SharePoint databases
    Recommended practices for SQL Server Analysis Services aggregations

    Microsoft SQL Server 2005
    End of life comes for SQL Server 2005 SP2, 2008
    SQL Server Reporting Services Fast Guide
    SQL Server Service Broker Tutorial and Reference Guide
    Tips for tuning SQL Server 2005 to improve reporting performance
    SQL Server consolidation: Why it's an optimization technique
    Parent-child dimensions in SQL Server 2005 with Analysis Services MDX
    Enforcing data integrity in a SQL Server database
    SSIS error message due to installation problem on SQL Server 2005
    Should you upgrade to SQL Server 2005 or SQL Server 2008?
    Basics for working with DATETIME and SMALLDATETIME in SQL Server 2005
    Microsoft SQL Server 2005 Research

    Microsoft SQL Server Database Development
    Change tempdb from 'C' drive
    MDX functions: SCOPE, THIS and FREEZE
    More powerful Analysis Services MDX in SQL Server 2005
    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
    Conversion error in SQL Server business objects
    Installing two instances of SQL Server 2005 on same server
    Microsoft SQL Server Database 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 technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online 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