Referencing Named Sets in Calculations
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.

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