【问题标题】:MDX : How to get dimension count for filtered membersMDX:如何获取过滤成员的维度计数
【发布时间】:2013-10-23 10:35:40
【问题描述】:
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]

结果:

在上面的查询中,如何获得有多少国家贡献了 A 类、B 类、C 类,这里对于任何类,最大国家数 6 显示在度量“Country Count”中?

为什么这里 existing 没有提供 current class 的国家数量?

【问题讨论】:

  • 感谢@Justin 格式化文本。

标签: sql-server-2012 ssas mdx


【解决方案1】:

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

以下查询有效(注意counts 在基本集上):

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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多