MDX:如何获取已过滤成员的维度计数

时间:2013-10-23 10:35:40

标签: sql-server-2012 ssas mdx

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]

结果:

Result

在上面的查询中,如何获取有多少国家/地区贡献A类,B类,C类,此处对于任何类别,在度量'国家/地区计数'中显示最大国家/地区数量6 ?

为什么现有不提供当前班级的国家/地区数量?

1 个答案:

答案 0 :(得分:1)

这不起作用,因为您在同一层次结构中工作:[Customer].[Customer Geography].ClassA是此层次结构的新成员,FIlter结果未包含在其中,因此EXISTING不起作用。

以下查询有效(请注意,count位于基本集上):

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]