MDX如何分组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MDX如何分组相关的知识,希望对你有一定的参考价值。
有人有想法解决我的问题吗?
我必须比较不同时期的一些值(30.12.2017 - 05.1.2018 / 30.12.2016 - 05.01.2017 / ...)因此我定义了一个mdx,每个时期设置为:
WITH
SET [Period 1] as { STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2017-12-30T00:00:00]"
: STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2018-01-04T00:00:00]" ) }
SET [Period 2] as { STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2016-12-30T00:00:00]" )
: STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2017-01-04T00:00:00]" ) }
SELECT
NON EMPTY { [Measures].[Average Price], [Measures].[Average Position] } ON COLUMNS,
NON EMPTY ( { [Period 1], [Period 2] } ) on rows
FROM [Cube]
当我想要每天的结果时,这是有效的,但我如何得到每个时期的值(平均值/总和)?所需的结果是对于Period 1有2行,对于Period 2有1行。
答案
您应该只能在WITH
子句中为每个应用聚合函数:
WITH
SET [Period 1] as
STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2017-12-30T00:00:00]"
:
STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2018-01-04T00:00:00]" )
SET [Period 2] as
STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2016-12-30T00:00:00]" )
:
STRTOMEMBER( "[Created].[Year - Month - Date].[Date].&[2017-01-04T00:00:00]" )
MEMBER [Created].[Year - Month - Date].[All].[Period 1 Agg] AS
AGGREGATE( [Period 1] )
MEMBER [Created].[Year - Month - Date].[All].[Period 2 Agg] AS
AGGREGATE( [Period 2] )
SELECT
NON EMPTY { [Measures].[Average Price], [Measures].[Average Position] } ON 0,
NON EMPTY
{
[Created].[Year - Month - Date].[All].[Period 1 Agg],
[Created].[Year - Month - Date].[All].[Period 2 Agg]
} on 1
FROM [Cube];
以上是关于MDX如何分组的主要内容,如果未能解决你的问题,请参考以下文章
SSAS MDX 计算度量 - [ITEMS] 的 COUNT 个。[Item] 分组 [Items].[Item Group]