2014-09-03 48 views
2

請考慮以下數據。我想獲得的非{國家:美國&性別:F}使用MDX如何執行MDX除了交叉連接尺寸查詢

 
- - - - - - - - - - - - - - - - - - - - - 
| Country  | Gender  | Sales |   
- - - - - - - - - - - - - - - - - - - - - 
USA    M    1000 
USA    F    500 
Spain    M    200 
Spain    F    600 

我想提取會是什麼:

 
- - - - - - - - - - - - - - - - - - - - - 
| Country  | Gender  | Sales |   
- - - - - - - - - - - - - - - - - - - - - 
USA    M    1000 
Spain    M    200 
Spain    F    600 

我試圖用交叉連接,工會和除了那樣做,例如

 

    WITH SET [Test] AS 
    [Country].[CountryCode].[USA] * Except ([Gender].members,{[Gender].[GenderCode].[F]}) + 
    Except([Country].[CountryCode].members, {[Country].[CountryCode].[USA]}) * [Gender].members 
    SELECT 
     NON EMPTY [Test] ON ROWS, 
     {[Measures].[Sales]} ON COLUMNS 
     FROM [SalesCube] 

它的工作,但我可以知道是否有任何其他更簡單的方法來做到這一點?

謝謝。

回答

1

如果要排除一些組合,可以使用Except在十字架上與例外組合參加像這樣的元組:

WITH SET [Test] AS 
Except(CrossJoin([Country].[CountryCode].members, 
       [Gender].members 
       ), 
     { ([Country].[CountryCode].[USA], [Gender].[GenderCode].[F]) } 
    ) 
... 

而且語法,你的縮寫CrossJoin*Except-,以及Union+,其具有優先的一般規則(*具有比-更高precendece和+):

WITH SET [Test] AS 
[Country].[CountryCode].members * [Gender].[GenderCode].members 
- 
{ ([Country].[CountryCode].[USA], [Gender].[GenderCode].[F]) } 
... 
+0

請記住,使用 - 而不是除去實際的集合元素去除,而只是減去度量值。 *是Crossjoin的簡寫符號,但 - 並不完全等同於Except。 – nsousa 2014-09-04 07:56:22

+0

@nsousa不!像'*'可以用作集合上的交叉連接運算符,也可以用作值上的乘法運算符,如果在集合上使用'-'則是'Except'的別名(請參閱在http:/下使用作爲set運算符的minus文檔。 /msdn.microsoft.com/en-us/library/ms145497.aspx)以及值的乘法運算符。 – FrankPl 2014-09-04 16:53:04

+0

你說得對,我的印象是錯誤的。感謝那。 – nsousa 2014-09-05 08:36:16