2016-12-02 74 views
0

我想根據查詢中先前派生的總列來計算表中的百分比行。MDX百分比行不能正確計算

有兩列,然後我創建該列的總數。在下一行,我想要顯示總數的百分比。輸出應該是這樣的:


   Life  Non-Life (P&C)  SumTotal 
Premiums 66,104.44  916,792.51  982,896.95 
Percentage  6.73%   93.27%    1 

但相反,第二行顯示爲零。

如何構建查詢以正確計算? 下面是MDX代碼:

with member [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].[SumTotal] as SUM([LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics] , [Measures].[Value] ) 

member [LocationSpecificData].[Data Type].[All].[Percentage] as [LocationSpecificData].[Data Type].[All].[Gross Written Premiums Total - Calculated], [Measures].[Value])/([LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].[SumTotal], [Measures].[Value] ) 

Select { [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].&[Life], [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].&[Non-Life (P&C)], [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].[SumTotal] } On Columns , 
{ [LocationSpecificData].[Data Type].[All].[Gross Written Premiums Total - Calculated] , [LocationSpecificData].[Data Type].[All].[Percentage] } On Rows 
FROM [CubeDatabase] 

回答

0

請嘗試下面的例子,這在我的環境中工作得很好。我已將日期維度[Datum]與年份屬性[Jahr]用於添加[Line2]以添加第二行。第一行顯示的是2016年。根據您的需要設置計算出的度量值[M1]和[M2],並相應地交換年度維度。

WITH 
MEMBER [Measures].[M1] AS [Measures].[name of your measure for col 1] 
MEMBER [Measures].[M2] AS [Measures].[name of your measure for col 2] 
MEMBER [Measures].[Total] AS [Measures].[M1] + [Measures].[M2] 

MEMBER [Datum].[Jahr].[Line2] AS 
    Divide(
     ([Datum].[Jahr].&[2016], [Measures].CurrentMember), 
     ([Datum].[Jahr].&[2016], [Measures].[Total]) 
    ) 

SELECT { 
    [Measures].[M1], 
    [Measures].[M2], 
    [Measures].[Total] 
} ON 0, 

{ 
    [Datum].[Jahr].&[2016], 
    [Datum].[Jahr].[Line2] 
} ON 1 

FROM [name of cube] 

在我的環境,結果是這樣的: enter image description here

+0

真棒。感謝堆。 –

+0

不客氣:)我稍微更新了'[Line2]'計算,現在是更好的解決方案。 –