THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | Join | Help
in Search

Microsoft OLAP by Mosha Pasumansky

AS2008 MDX: subselects and CREATE SUBCUBE in non-visual mode

There were not very many changes to MDX syntax in AS2008, and Vidas Matelis described most of them in his blog here (for his list of all changes in AS2008 check this blog entry). I just noticed that there is at least one more change which Vidas didn’t include, but which is somewhat important: ability to define CREATE SUBCUBE and subselects in non visual mode.

To understand this, we need to understand what CREATE SUBCUBE does. It really does two things:

1. Implicit Exists between the set in CREATE SUBCUBE and query axis, query named sets including top level set functions (for more details see blog "Slicer and axis interaction in MDX Part 2 - Implicit Exists" – even though it talks about WHERE clause, everything from that entry equally applies to subselects and CREATE SUBCUBE as well)

2. Applies visual totals to the values of physical measures even within expressions if there are no coordinate overwrites.

Let’s look into this deeper. Consider the following example:

CREATE SUBCUBE [Adventure Works] AS 
 (SELECT 
    {
       [Customer].[Customer Geography].[City].&[Redmond]&[WA]
      ,[Customer].[Customer Geography].[City].&[Seattle]&[WA]
    } ON 0 
  FROM [Adventure Works])

We are creating filter to include only two cities – Redmond and Seattle. Now if we send the following query:

WITH 
 MEMBER [Measures].[Gross Margin] AS [Measures].[Internet Gross Profit]/[Measures].[Internet Sales Amount]
   ,FORMAT_STRING = 'Percent' 
SELECT {[Measures].[Internet Sales Amount], [Measures].[Internet Gross Profit],[Measures].[Gross Margin]} ON 0
, [Customer].[City].MEMBERS ON 1
FROM [Adventure Works]
  Internet Sales Amount Internet Gross Profit Gross Margin
All Customers $153,989.23 $64,075.99 41.61%
Redmond $78,824.37 $33,150.36 42.06%
Seattle $75,164.86 $30,925.63 41.14%

We will observe two things. First, we only get two cities on row axis – that’s the implicit exists part. Second, the values for physical measure Internet Sales Amount, cube defined calculated measure Internet Gross Profit and query defined calculated measure Gross Margin – are all visual totals, i.e. they all are computed using data for only two cities defined by the CREATE SUBCUBE command.

AS2008 adds capability to only keep implicit exists behavior, and to return real totals as opposed to visual totals. The syntax is described in MSDN documentation and in our example it will be (note that NON VISUAL keywords)

CREATE SUBCUBE [Adventure Works] AS NON VISUAL
 (SELECT 
    {
       [Customer].[Customer Geography].[City].&[Redmond]&[WA]
      ,[Customer].[Customer Geography].[City].&[Seattle]&[WA]
    } ON 0 
  FROM [Adventure Works])

Now if we execute the same query, the result is different:

  Internet Sales Amount Internet Gross Profit Gross Margin
All Customers $29,358,677.22 $12,080,883.65 41.15%
Redmond $78,824.37 $33,150.36 42.06%
Seattle $75,164.86 $30,925.63 41.14%

The implicit exists still happens, we see only two cities, but there is no visual totals anymore. Both physical and calculated measures are computed now as if there were no CREATE SUBCUBE. Same functionality applies also to subselects (documented on MSDN here).

Why is this important ? Remember, that Excel 2007 uses subselects to implement multiselect functionality. However, since subselects only supported visual totals mode before AS2008, Excel team was forced to remove ability to show non-visual totals in PivotTables. This caused users dissatisfaction, since users wanted to have control over numbers in PivotTables, just like with previous versions of Excel and Analysis Services. This problem is well documented, for example in "Common Questions Around Excel 2007 OLAP PivotTables" blog entry by Allan Folting from Excel team. So implementing NON VISUAL mode in AS2008 is a key enabling feature to Excel to be able to restore this PivotTables functionality in the future releases.


Published Tuesday, November 04, 2008 12:22 AM by mosha
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Vidas Matelis said:

Mosha,

Thank you, this is quite interesting. I updated my posts to include info you posted here.

November 4, 2008 7:09 PM
 

hank said:

Hi Mosha,

I have seen some strang behavior of AS2008. For example, if i want to overwrite a year level measure with null, the following first statement does not work correctly. It seems overwriting other measures in the measure group as well. I have to use second statement to get right result. The first statement works fine in AS2005. what has changed? why?

try one. not working in AS2008. work in AS2005.

scope([Measures].[Internet Sales Amount],[Ship Date].[Calendar].[Calendar Year]);

this =null;

end scope;

try two. work in AS2008.

scope([Ship Date].[Calendar].[Calendar Year]);

if [Measures].currentmember is [Measures].[Internet Sales Amount]

then this =null

end if;

end scope;

thanks

hank

November 17, 2008 10:47 AM
 

Creating Sub Cubes - Visual and Non Visual Mode « SQL Kit said:

March 20, 2009 8:07 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement