2013-07-16 46 views
4

在行上,我基本上想要選擇層次結構的所有成員,但希望將其中的兩個合併爲一個。例如,成員將包括ABC,所以選擇[Group].[Group].members會給我AllABC但我想獲得All, A,B&C,其中BC已合併爲一個成員。如何在查詢中將兩個成員合併爲一個成員?

這是可能的查詢內?

我正在使用的數據庫存儲有關訂單的運輸速度,小包裹,小於卡車裝載量和白手套的信息。我想合併小包裹和小於卡車的載重量,這樣我就可以在兩種運輸速度中獲得彙總數據。

我試着創建一個計算成員:[Measures].[Not White Glove] as AGGREGATE([Order Product].[Ships Via Group].&[Small Parcel], [Order Product].[Ships Via Group].&[Less than Truck Load])但我不確定如何使用,因爲我目前有[Order Product].[Ships Via Group].members ON ROWS

當我把([Measures].[Not White Glove], [Order Product].[Ships Via Group].&[White Glove], [Order Product].[Ships Via Group].&[All]) ON ROWS我得到的錯誤Query (14, 11) The Ships Via Group hierarchy is used more than once in the Crossjoin function.

有沒有更好的辦法去了解這個/是什麼錯誤呢?

+0

你想達到什麼目的? (爲什麼你應該合併兩行,並在哪個基礎上/哪些條件下應該合併?)你嘗試過什麼? – Pieter

+0

爲問題添加了更多信息,解決了您提出的問題。對不起,以前沒有提供更多信息 – Travis

回答

9

你看到的錯誤是因爲你的語法和圓括號:(a, b, c)定義了一個元組,其中a,b和c是來自不同維度的每個成員。如果您嘗試將這些成員結合在一起,則應使用簡寫:{a, b, c}

現在,結合成員是可能的,雖然也許不像你想要的那樣乾淨和容易。以下是創建新成員的一種方法的示例,然後從層次結構中排除(通過Except)原始成員。

WITH 
    SET [Combined] AS { 
     [Customer].[Customer Geography].[Country].&[France], 
     [Customer].[Customer Geography].[Country].&[Germany] 
    } 
    MEMBER [Customer].[Customer Geography].[France & Germany] AS Aggregate([Combined]) 
SELECT 
    [Measures].[Internet Sales Amount] ON 0, 
    Union(
     Except([Customer].[Customer Geography].[Country], [Combined]), 
     [Customer].[Customer Geography].[France & Germany] 
    ) ON 1 
FROM [Adventure Works] 

結果:

    Internet Sales Amount 
Australia     $9,061,000.58 
Canada     $1,977,844.86 
United Kingdom   $3,391,712.21 
United States    $9,389,789.51 
France & Germany   $5,538,330.05 

希望幫助您設置在正確的軌道上。

+0

這非常有幫助!謝謝! – Travis

+0

我已經爲計算成員嘗試了此解決方案,並且在結果中出現#Error,並顯示消息「集合函數不能用於度量維度中的計算成員」。有任何想法嗎? – Neo

+0

謝謝。這個語法也適用於Mondrian。 –