Blog Post

MDX - Calculating the Percent of a Named Set

,

Getting the percent of something in MDX seems like a pretty easy task but can be complicated when extra logic is needed to be built in.  In this example a named set has been added and the requirement is to bring back the top 10 product sales and display the percent of each across all products (including products that are not part of the top 10).  If you're not careful here you could easily return back the top 10 product correctly but show the percentage of the products sales across only top 10.  Here's a couple example of both ways.

This example shows the percentage for each product sales divided by the over all sales (Product Sales/All Product Sales)

With Set Top10 AS  
TopCount([Product].[Product].Children,  
10,
[Measures].[Reseller Order Count])   
Member [Measures].[PercentSold] AS  
([Measures].[Reseller Order Count])/([Product].[Product].[All Products],[Measures].[Reseller Order Count]), Format_String ="Percent" 
Select {[Measures].[Reseller Order Count],[Measures].[PercentSold]}  on 0,  
Top10 on 1  
From [Adventure Works] 

 This example shows the percentage for each product sales divided by the top 10 products sales (Product Sales/Top 10 Product Sales)

With Set Top10 AS  
TopCount([Product].[Product].Children,  
10,
[Measures].[Reseller Order Count])   
Member [Measures].[PercentTopSold] AS
[Measures].[Reseller Order Count]/SUM([Top10],[Measures].[Reseller Order Count]), Format_String ="Percent" 
Select {[Measures].[Reseller Order Count],[Measures].[PercentTopSold]}  on 0,  
Top10 on 1  
From [Adventure Works] 

 

 

 

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating