MDX按维度排序

时间:2016-03-07 19:49:03

标签: sorting mdx pentaho

在SQL方面,我的数据看起来像这样:

Select f.id, f.TimeKey,t.CalendarYearMonth 
from FactSubmission f
inner join DimTime t on t.TimeKey = f.TimeKey
order by f.Id asc

enter image description here

从MDX排序我们有下降

SELECT
NON EMPTY ORDER(
 [DimTime.CalendarYearMonth].[CalendarYearMonth].Members,
 [DimTime.CalendarYearMonth].CurrentMember.Properties("MEMBER_KEY"), 
 DESC
 )  ON COLUMNS
FROM [PSE_FactSubmission]

enter image description here

升序

enter image description here

1月份的日期不在任何一种排名的顶部,这表示我按FactSubmission.ID键而不是DimTime.CalendarYearMonth排序

这是事情应该如何运作?我想退回1月,2月,3月。

DimTime.CalendarYearMonthNum是一个包含201501,201502,201503等形式数据的列。这里尝试使用此列对CalendarYearMonth数据进行排序。

enter image description here

调试查询以选择键 enter image description here

非空查询 enter image description here

2 个答案:

答案 0 :(得分:0)

尝试使用其他属性进行排序:

SELECT
NON EMPTY ORDER(
 [DimTime.CalendarYearMonth].[CalendarYearMonth].Members,
 [DimTime.CalendarYearMonth].CurrentMember.Properties("MEMBER_Value"), 
 DESC
 )  ON COLUMNS
FROM [PSE_FactSubmission];

或者这个:

SELECT
NON EMPTY ORDER(
 [DimTime.CalendarYearMonth].[CalendarYearMonth].Members,
 [DimTime.CalendarYearMonth].CurrentMember.MEMBERValue, 
 DESC
 )  ON COLUMNS
FROM [PSE_FactSubmission];

在上面你应该善于使用DESC - 有时你需要通过添加B来打破基础层次排序,即BDESC

从这里我看不到MEMBER_VALUEhttp://mondrian.pentaho.com/documentation/mdx.php

...但是有一个函数.VALUE所以请尝试以下方法:

SELECT
NON EMPTY ORDER(
 [DimTime.CalendarYearMonth].[CalendarYearMonth].Members,
 [DimTime.CalendarYearMonth].CurrentMember.Value, 
 DESC
 )  ON COLUMNS
FROM [PSE_FactSubmission];

奇怪的是钥匙不起作用。如果你运行这样的东西,你会得到什么价值?

WITH MEMBER [KEYcheck] AS
    [DimTime.CalendarYearMonth].CurrentMember.Properties("MEMBER_KEY")
    //[DimTime.CalendarYearMonth].CurrentMember.MEMBER_KEY
    //[DimTime.CalendarYearMonth].[CalendarYearMonth].CurrentMember.MEMBER_KEY
    //[DimTime].CurrentMember.MEMBER_KEY
SELECT
  [KEYcheck] ON 0,
  [DimTime.CalendarYearMonth].[CalendarYearMonth].Members ON 1
FROM [PSE_FactSubmission];

答案 1 :(得分:0)

您正在按字母顺序排序。的˚F ebruary->的Ĵ anuary->的中号

要根据月份编号进行排序,需要有一个映射1月1日,2月2日,3月3日的字段。

如果您在立方体中有这样的列,请使用它来进行排序。如果没有创建如下的计算成员 -

WITH MEMBER Measures.CalendarMonth AS
CASE [DimTime.CalendarYearMonth].CurrentMember
 WHEN  [DimTime.CalendarYearMonth].&[January] THEN 1
 WHEN  [DimTime.CalendarYearMonth].&[February] THEN 2
 WHEN  [DimTime.CalendarYearMonth].&[March] THEN 3
END

SELECT
NON EMPTY ORDER(
 [DimTime.CalendarYearMonth].[CalendarYearMonth].Members,
 Measures.CalendarMonth, 
 DESC
 )  ON COLUMNS
FROM [PSE_FactSubmission]

编辑Andrew

with member Measures.[MonthNum] as
NonEmpty
    ( 
     [DimTime.CalendarYearMonthNum].[CalendarMonthNum].members,
     ([DimTime.CalendarYearMonth].[CalendarYearMonth].currentmember, Measures.foo)
    ).item(0).membervalue

select
non empty
order
  (
   [DimTime.CalendarYearMonth].[CalendarYearMonth].members,
   Measures.[MonthNum],
   desc
  ) on rows
from [PSE_FactSubmission]

编辑 - EXISTS

with member Measures.[MonthNum] as
EXISTS
      (
       [DimTime.CalendarYearMonthNum].[CalendarMonthNum].members,
       [DimTime.CalendarYearMonth].[CalendarYearMonth].currentmember,
       "SomeMeasureGroup"
      ).item(0).membervalue