MDX 按月排序

MDX Sort By Month

我正在尝试整理我对 pentaho CDE 仪表板图表的第一个查询。

开始查询

WITH 
  SET [~COLUMNS] AS 
    {[DimProgram.Name].[Name].MEMBERS} 
  SET [~ROWS] AS 
    {[DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS} 
SELECT 
  NON EMPTY 
    CrossJoin
    (
      [~COLUMNS]
     ,{[Measures].[SubmissionCount]}
    ) ON COLUMNS
 ,NON EMPTY 
    [~ROWS] ON ROWS
FROM [PSE_FactSubmission];

此查询 returns 我想要的数据,但需要稍微调整一下才能为实际使用做好准备。我想按日期降序排序并限制为过去 12 个月。

我已经阅读了几个关于在 MDX 中排序的网页,但无法将 运行 的查询放在一起。当查询不 运行 只是一个 "Error" 提示时。

订购尝试

WITH 
  SET [~COLUMNS] AS 
    {[DimProgram.Name].[Name].MEMBERS} 
SELECT 
  NON EMPTY 
    CrossJoin
    (
      [~COLUMNS]
     ,{[Measures].[SubmissionCount]}
    ) ON COLUMNS
 ,NON EMPTY 
    Order
    (
      [DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS
     ,[DimTime.CalendarYearMonth].CurrentMember.Member_Key
     ,DESC
    ) ON ROWS
FROM [PSE_FactSubmission];

任何有关排序或如何限制过去 X 个月的提示都将不胜感激。

通常 Date/Time 维度在立方体设计中自然排序,因此无需使用 Order。我不需要使用我使用的多维数据集。

如果它在立方体中的顺序很奇怪,那么您需要使用 BASCBDESC:

打破 (B) 这种层次顺序
WITH 
  SET [~COLUMNS] AS 
    {[DimProgram.Name].[Name].MEMBERS} 
  MEMBER [Measures].[orderMeas] AS 
    [DimTime.CalendarYearMonth].CurrentMember.Member_Key 
  SET [~ROWS] AS 
    Order
    (
      [DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS
     ,[Measures].[orderMeas]
     ,BASC
    ) 
SELECT 
  NON EMPTY 
    CrossJoin
    (
      [~COLUMNS]
     ,{[Measures].[SubmissionCount]}
    ) ON COLUMNS
 ,NON EMPTY 
    [~ROWS] ON ROWS
FROM [PSE_FactSubmission];

要获取最近 12 个月的数据,您可以使用 Tail 函数 - 最好将其用于 NonEmpty 月份:

WITH 
  SET [~COLUMNS] AS 
    {[DimProgram.Name].[Name].MEMBERS} 
  MEMBER [Measures].[orderMeas] AS 
    [DimTime.CalendarYearMonth].CurrentMember.Member_Key 
  SET [~ROWS] AS 
    Order
    (
      NonEmpty
      (
        [DimTime.CalendarYearMonth].[CalendarYearMonth].MEMBERS
       ,[Measures].[SubmissionCount]
      )
     ,[Measures].[orderMeas]
     ,BASC
    ) 
SELECT 
  NON EMPTY 
    CrossJoin
    (
      [~COLUMNS]
     ,{[Measures].[SubmissionCount]}
    ) ON COLUMNS
 ,NON EMPTY 
    Tail
    (
      [~ROWS]
     ,12
    ) ON ROWS
FROM [PSE_FactSubmission];

嗨,安德鲁 - 针对 AdvWrks 我得到了以下 运行,没有任何错误。我需要将 Member_Key 更改为 MemberValue:

WITH 
  SET [~COLUMNS] AS 
    [Product].[Product Categories].[Product]
  MEMBER [Measures].[orderMeas] AS 
    [Date].[Calendar].CurrentMember.MemberValue 
  SET [~ROWS] AS 
    Order
    (
      NonEmpty
      (
        [Date].[Calendar].[Month].MEMBERS
       ,[Measures].[Internet Sales Amount]
      )
     ,[Measures].[orderMeas]
     ,ASC
    ) 
SELECT 
  NON EMPTY 
    CrossJoin
    (
      [~COLUMNS]
     ,{[Measures].[Internet Sales Amount]}
    ) ON COLUMNS
 ,NON EMPTY 
    Tail
    (
      [~ROWS]
     ,12
    ) ON ROWS
FROM [Adventure Works];