MDX Aggregate Named Set Than Others

In this quick post I wanted to provide some code that’s been useful to me recently.  This MDX statement creates a named set of the Top 20 products and then aggregates on a selected measure.  Commonly though you may want to return an aggregation on those Top 20 products but optionally have an Others member that displays the aggregated sales for all other products not included in the set.

My explanation might be more confusing than my code so here it is!  You can run it against the Adventure Works cube to simulate the results.

With 
Set [Top20Products] AS 
(TOPCOUNT({ ORDER( HIERARCHIZE( {[Product].[Product].[All].Children}), ([Measures].[Internet Sales Amount]), BDESC ) }, 20))  

MEMBER [Product].[Product].[Other Products] AS  
(AGGREGATE({EXCEPT([Product].[Product].Members, [Product].[Product].[Top20Products])}))  

Select [Measures].[Internet Sales Amount] on 0,  
{[Top20Products],[Product].[Product].[Other Products]}on 1  
From [Adventure Works]

 

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