MDX如何分组

问题描述 投票:0回答:1

有人有想法解决我的问题吗?

我必须比较不同时期的一些值(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行。

sum set average mdx
1个回答
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];
© www.soinside.com 2019 - 2024. All rights reserved.