2
votes

I'm just starting to get my head around MDX and I'm having trouble with a calculated member. I'm using the following MDX:

IIF( ISEMPTY((Axis(1).Item(0).Item(0).Dimension.CurrentMember, [Measures].[Qty])) ,NULL ,([Product].[Product Code].CurrentMember.Parent, [Measures].[Qty])

)

What I'm trying to do is get a total quantity of the group of products displayed in a cube. I then use that total to divide by each product's quantity to get a "percent of total" measure. The above MDX does correctly return the total quantity of products displayed in any dimension. However, when a user in Excel changes the filter on which products are displayed, the MDX above still displays the total quantity for the whole group, ignoring which products the user has checked. I assume I'm lacking some basic understanding of MDX, how do I get the calculated measure to account for the product codes the user has selected in Excel?

1

1 Answers

0
votes

With Visual Studio SQL Server Data Tools (if you are using that tool), you can browse to your cube, select the Calculations tab, and under Calculations Tools > Templates there is a template "Percentage of Total". The MDX this tool provides is flexible so that the percentage adjusts with the attributes of the hierarchy you've pulled into the pivot.

Case
// Test to avoid division by zero.
When IsEmpty
 ( 
    [Measures].[<<Target Measure>>] 
 ) 
Then Null

Else ( [<<Target Dimension>>].[<<Target Hierarchy>>].CurrentMember,
   [Measures].[<<Target Measure>>] ) 
 /
 ( 
   // The Root function returns the (All) value for the target dimension.
   Root     
   ( 
      [<<Target Dimension>>] 
    ), 
    [Measures].[<<Target Measure>>] 
 )
End

I found this option to work when developing to achieve what you've mentioned.