Chris Webb's BI Blog

Analysis Services, MDX, PowerPivot, DAX and anything BI-related

Referencing Named Sets in Calculations

with 2 comments

I was recently involved in an interesting discussion about the negative performance impact of referencing named sets inside calculated members. It’s an issue that’s dealt with in this topic in BOL, along with lots of other useful tips for things to avoid when writing MDX calculations:
http://msdn.microsoft.com/en-us/library/bb934106.aspx

Since I see lots of people making this mistake, though, I thought it was nonetheless worth a blog post; it’s certainly very easy to reproduce in Adventure Works. Take the following set of calculations:

CREATE SET ALLCUSTS AS [Customer].[Customer].[Customer].MEMBERS;

CREATE MEMBER CURRENTCUBE.MEASURES.TEST1 AS 
COUNT(
NONEMPTY(
[Customer].[Customer].[Customer].MEMBERS
, [Measures].[Internet Sales Amount])
);

CREATE MEMBER CURRENTCUBE.MEASURES.TEST2 AS 
COUNT(
NONEMPTY(
ALLCUSTS
, [Measures].[Internet Sales Amount])
);

CREATE MEMBER CURRENTCUBE.MEASURES.TEST3 AS 
SUM(
[Customer].[Customer].[Customer].MEMBERS
, [Measures].[Internet Sales Amount]);

CREATE MEMBER CURRENTCUBE.MEASURES.TEST4 AS 
SUM(
ALLCUSTS
, [Measures].[Internet Sales Amount]);

 

You’ll notice that TEST1 and TEST2 are essentially the same calculation, as are TEST3 and TEST4; the only difference between them is that the set expressions in TEST1 and TEST3 have been replaced by references to the named set ALLCUSTS in TEST2 and TEST4.

Now run the following query four times on a cold cache, each time putting a different calculated measure from the list above in the WHERE clause:

SELECT [Date].[Calendar Year].MEMBERS ON 0,
[Product].[Product].MEMBERS ON 1
FROM [Adventure Works]
WHERE(MEASURES.TEST1)
 

On my machine the query with TEST1 took 874ms to run; the query with TEST2 took 6302ms; the query with TEST3 took 234ms; and the query with TEST4 I ended up killing after a few minutes.

So, clearly, as the article says referencing a named set inside one of the MDX aggregation functions in a calculation is a Very Bad Thing for performance and something to be avoided at all costs. While it might seem an appealing thing to do for readability, the downsides are significant.

Written by Chris Webb

March 16, 2011 at 8:12 pm

Posted in MDX

2 Responses

Subscribe to comments with RSS.

  1. And the real problem is that dynamic sets (which are the only generally working solution to the multiselect problems) suffer from the performance penalty.
    Honestly saying, I don’t quite understand where SSAS takes the wrong path. MDX Studio, for instance, provides the same statistics for [Customer].[Customer].[Customer].MEMBERS, SET and DYNAMIC SET (except the time of course):

    Cold cache execution
    Time : 11 sec 802 ms
    Calc covers : 0
    Cells calculated : 2388
    Sonar subcubes : 2404
    NON EMPTYs : 2394
    Autoexists : 0
    EXISTINGs : 0
    SE queries : 2398
    Flat cache insert : 1
    Cache hits : 2399
    Cache misses : 4
    Cache inserts : 3
    Cache lookups : 2403
    Memory Usage KB : 29612

    Warm cache execution

    Time : 10 sec 270 ms
    Calc covers : 0
    Cells calculated : 2388
    Sonar subcubes : 2402
    NON EMPTYs : 2394
    Autoexists : 0
    EXISTINGs : 0
    SE queries : 2394
    Flat cache insert : 1
    Cache hits : 2398
    Cache misses : 0
    Cache inserts : 0
    Cache lookups : 2398
    Memory Usage KB : -1928

    Looks more like a documented bug (i.e. a feature ;) ) for me

    Andrej Kuklin

    March 18, 2011 at 4:37 pm

    • Dynamic sets are the subject of a forthcoming post… but yes, it’s crazy that one of the few solutions to the multiselect problem suffer from performance issues.

      Chris Webb

      March 18, 2011 at 10:19 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 703 other followers