MDX:生成 2 个成员 'old clients' & 'new cliends' 并显示他们的销售统计数据
MDX: generate 2 members 'old clients' & 'new cliends' and show sales stats for them
首先,我需要将所有客户分为两类:
- 'new client' - 2015 年
- 'old client' - 2000-2014年
为此 - 我将它们推入不相关的维度 'Calendar'。它工作正常(同时将它们推到原始 [Client] 维度 - 会引发错误,我已经检查过了)。但是,在这些计算成员被提升后,我无法获得他们的销售统计数据。这是我的代码:
WITH
MEMBER [Calendar].[Year].[new clients] AS ([Calendar].[All], {[Client].[Year come].&[2015-01-01]})
MEMBER [Calendar].[Year].[old clients] AS ([Calendar].[All], {[Client].[Year come].&[2000-01-01]:
[Client].[Year come].&[2014-01-01]})
SET [Client type] AS {[Calendar].[Year].[new clients],
[Calendar].[Year].[old clients]}
SELECT [Measures].[Sales] ON COLUMNS,
NON EMPTY [Client type] ON ROWS
FROM [CUBE]
这是它给出的结果:
如果我用原始维度 [Client].[Year come] 替换计算集 [Client type],即从
更改 1 个代码行
NON EMPTY [Client type] ON ROWS
到
NON EMPTY [Client].[Year come] ON ROWS
然后 mdx 输出结果很好,没有错误:
但我需要将 [Measures].[Sales] 中的数据分成两行:老客户和新客户。不是每年都有客户来公司。我该怎么做?
我认为您的脚本已经基本完成 - 只需尝试在元组周围添加聚合:
WITH
MEMBER [Calendar].[Year].[new clients] AS
Aggregate(([Calendar].[All],[Client].[Year come].&[2015-01-01]))
MEMBER [Calendar].[Year].[old clients] AS
Aggregate
(
(
[Calendar].[All]
,{
[Client].[Year come].&[2000-01-01] : [Client].[Year come].&[2014-01-01]
}
)
)
SET [Client type] AS
{
[Calendar].[Year].[new clients]
,[Calendar].[Year].[old clients]
}
SELECT
[Measures].[Sales] ON COLUMNS
,NON EMPTY
[Client type] ON ROWS
FROM [CUBE];
这是对 @whytheq 回答的宝贵补充。 MSDN article for Aggregate() function 中的示例使用此条件:
WHERE [Mearsures].[Your measure]
我没有使用 WHERE,因为我已经对列进行了度量。这就是为什么我尝试将 Filter() func 添加到行 select:
NON EMPTY FILTER([Client type], [Measures].[Sales] > 0) ON ROWS
这从根本上提高了 mdx 速度并使 Aggregate() 函数的使用绝对舒适。但在那之后,当我添加了十几个其他措施时,——速度再次急剧下降!有什么想法可以解决这个生产力问题吗?
首先,我需要将所有客户分为两类:
- 'new client' - 2015 年
- 'old client' - 2000-2014年
为此 - 我将它们推入不相关的维度 'Calendar'。它工作正常(同时将它们推到原始 [Client] 维度 - 会引发错误,我已经检查过了)。但是,在这些计算成员被提升后,我无法获得他们的销售统计数据。这是我的代码:
WITH
MEMBER [Calendar].[Year].[new clients] AS ([Calendar].[All], {[Client].[Year come].&[2015-01-01]})
MEMBER [Calendar].[Year].[old clients] AS ([Calendar].[All], {[Client].[Year come].&[2000-01-01]:
[Client].[Year come].&[2014-01-01]})
SET [Client type] AS {[Calendar].[Year].[new clients],
[Calendar].[Year].[old clients]}
SELECT [Measures].[Sales] ON COLUMNS,
NON EMPTY [Client type] ON ROWS
FROM [CUBE]
这是它给出的结果:
如果我用原始维度 [Client].[Year come] 替换计算集 [Client type],即从
更改 1 个代码行NON EMPTY [Client type] ON ROWS
到
NON EMPTY [Client].[Year come] ON ROWS
然后 mdx 输出结果很好,没有错误:
但我需要将 [Measures].[Sales] 中的数据分成两行:老客户和新客户。不是每年都有客户来公司。我该怎么做?
我认为您的脚本已经基本完成 - 只需尝试在元组周围添加聚合:
WITH
MEMBER [Calendar].[Year].[new clients] AS
Aggregate(([Calendar].[All],[Client].[Year come].&[2015-01-01]))
MEMBER [Calendar].[Year].[old clients] AS
Aggregate
(
(
[Calendar].[All]
,{
[Client].[Year come].&[2000-01-01] : [Client].[Year come].&[2014-01-01]
}
)
)
SET [Client type] AS
{
[Calendar].[Year].[new clients]
,[Calendar].[Year].[old clients]
}
SELECT
[Measures].[Sales] ON COLUMNS
,NON EMPTY
[Client type] ON ROWS
FROM [CUBE];
这是对 @whytheq 回答的宝贵补充。 MSDN article for Aggregate() function 中的示例使用此条件:
WHERE [Mearsures].[Your measure]
我没有使用 WHERE,因为我已经对列进行了度量。这就是为什么我尝试将 Filter() func 添加到行 select:
NON EMPTY FILTER([Client type], [Measures].[Sales] > 0) ON ROWS
这从根本上提高了 mdx 速度并使 Aggregate() 函数的使用绝对舒适。但在那之后,当我添加了十几个其他措施时,——速度再次急剧下降!有什么想法可以解决这个生产力问题吗?