2015-03-25 58 views
1

在我的立方體中,我有一個事實訂單行,其變量爲訂單成本。這個變量當然是每個訂單唯一的,並且在訂單的每個訂單行中具有相同的值。從MDX中的訂單行獲取訂單成本

現在我想創建一個總計訂單成本的計算字段,但每個訂單隻取這個值一次。

所以,使用計算出的構件此

+-------------------+--------------+------------+    
| Order Line Number | Order Number | Order Line | 
|     |    | Order Cost | 
+-------------------+--------------+------------+ 
|    10 |   1 | $0.20  | 
|    11 |   1 | $0.20  | 
|    20 |   2 | $0.25  | 
+-------------------+--------------+------------+ 

有可能成爲該

+--------------+------------+ 
| Order Number | Order Cost | 
+--------------+------------+ 
|   1 | $0.20  | 
|   2 | $0.25  | 
+--------------+------------+ 

MDX表達式我現在有(見下文),求和通過順序線,使得訂單成本訂單編號1爲0.40美元。

SUM( 
    DISTINCT( 
     CROSSJOIN(
      [Order Line Details].[Order Number].[All].Children, [Measures].[Order Line Order Cost] 
     ) 
    ) 
) 

我需要更改以獲得所需的行爲?

請讓我知道,如果有什麼不清楚的問題。

解決方案

好吧,我發現這個問題。我將聚集行爲從[Measures]。[Order Line Order Cost]改爲min。之後,你的初始解決方案工作。謝謝您的幫助!

回答

0

以下是否有效?我擺脫了不必要的crossjoin,並將distinct函數放在[Order Line Details].[Order Number].Children上,並使用SUM函數將Order Line Order Cost與訂單號碼相加。

SUM(
    DISTINCT([Order Line Details].[Order Number].Children) 
    , [Measures].[Order Line Order Cost] 
    ) 

編輯 試試下面的代碼:

WITH 
SET DistinctOrderNumbers AS 
DISTINCT(EXISTING [Order Line Details].[Order Number].Children) 

MEMBER [Measures].[Order Cost] AS 
SUM(DistinctOrderNumbers, [Measures].[Order Line Order Cost]) 

SELECT NON EMPTY { [Measures].[Order Cost] } ON COLUMNS, 
NON EMPTY { ([Reseller].[Reseller].[Reseller].ALLMEMBERS) } ON ROWS 
FROM [BI Cube] 

EDIT2(不平均之和)

WITH 
SET DistinctOrderNumbers AS 
DISTINCT(EXISTING [Order Line Details].[Order Number].Children) 

MEMBER [Measures].[Order Cost] AS 
AVG(DistinctOrderNumbers, [Measures].[Order Line Order Cost]) 

SELECT NON EMPTY { [Measures].[Order Cost] } ON COLUMNS, 
NON EMPTY { ([Reseller].[Reseller].[Reseller].ALLMEMBERS) } ON ROWS 
FROM [BI Cube] 
+0

不,它仍將所有訂單行上的[訂單行訂單成本]相加。 – Raymond 2015-03-31 14:07:25

+0

什麼是您使用的整個MDX查詢? – SouravA 2015-03-31 14:15:07

+0

'WITH MEMBER [Measures]。[Order Cost] AS SUM(DISTINCT([Order Line Details]。[Order Number] .Children),[Measures]。[Order Line Order Cost]) SELECT \t NON EMPTY { ([Reseller]。[Reseller]。[Reseller] .ALLMEMBERS)} ON ROWS \t FROM [BI Cube]' – Raymond 2015-03-31 14:48:20

0

請嘗試以下:

MIN( 
    [Order Line Details].[Order Number].[All].Children 
    ,[Measures].[Order Line Order Cost] 
    )