2013-10-23 130 views
0
WITH MEMBER [Measures].[Country Count] 
AS 
Count(existing [Customer].[Customer Geography].[Country]) 

MEMBER [Customer].[Customer Geography].ClassA AS 
SUM(filter([Customer].[Customer Geography].[Country],[Measures].[Internet Order Count] > 3000)) 

MEMBER [Customer].[Customer Geography].ClassB AS 
SUM(filter([Customer].[Customer Geography].[Country],[Measures].[Internet Order Count] > 1500)) 


MEMBER [Customer].[Customer Geography].ClassC AS 
SUM(filter([Customer].[Customer Geography].[Country],[Measures].[Internet Order Count] > 0)) 

SET My_Custom_Set AS 
{[Customer].[Customer Geography].ClassA, [Customer].[Customer Geography].ClassB,[Customer].[Customer Geography].ClassC} 

SELECT {[Measures].[Internet Order Count], [Measures].[Internet Sales Amount], [Measures].[Country Count]} ON COLUMNS, 
My_Custom_Set ON ROWS 
FROM 
[Adventure Works] 

結果:MDX:如何獲得的尺寸計數過濾成員

Result

在上面的查詢,如何獲得多少國家作出貢獻的A類,B類,C類,在這裏,對於任何班級,最大國家數量6顯示在度量「國家計數」中?

爲什麼在這裏現有是不是提供國家的計數當前類

+0

感謝@Justin格式化文本。 –

回答

1

這不起作用,因爲您在相同的層次結構中工作:[Customer].[Customer Geography].ClassA是此層次結構的新成員,並且FIlter結果不包含在其中,因此EXISTING不起作用。

下面的查詢工作(注意:count s爲在基套):

WITH 
SET ClassA AS 
filter([Customer].[Customer Geography].[Country],[Measures].[Internet Order Count] > 3000) 

SET ClassB AS 
filter([Customer].[Customer Geography].[Country],[Measures].[Internet Order Count] > 1500) 

SET ClassC AS 
filter([Customer].[Customer Geography].[Country],[Measures].[Internet Order Count] > 0) 

MEMBER [Customer].[Customer Geography].ClassA AS 
SUM(ClassA) 

MEMBER [Customer].[Customer Geography].ClassB AS 
SUM(ClassB) 

MEMBER [Customer].[Customer Geography].ClassC AS 
SUM(ClassC) 

MEMBER [Measures].[Country Count] 
AS 
CASE 
    WHEN [Customer].[Customer Geography].CurrentMember IS [Customer].[Customer Geography].ClassA THEN 
     ClassA.Count 
    WHEN [Customer].[Customer Geography].CurrentMember IS [Customer].[Customer Geography].ClassB THEN 
     ClassB.Count 
    WHEN [Customer].[Customer Geography].CurrentMember IS [Customer].[Customer Geography].ClassC THEN 
     ClassC.Count 
    WHEN [Customer].[Customer Geography].CurrentMember IS [Customer].[Customer Geography].[All Customers] THEN 
     [Customer].[Customer Geography].[Country].Count 
    ELSE 
     1 
END 


SET My_Custom_Set AS 
{[Customer].[Customer Geography].ClassA, [Customer].[Customer Geography].ClassB,[Customer].[Customer Geography].ClassC} 

SELECT {[Measures].[Internet Order Count], [Measures].[Internet Sales Amount], [Measures].[Country Count]} ON COLUMNS, 
My_Custom_Set ON ROWS 
FROM 
[Adventure Works]