【问题标题】:MDX Ordering By DimensionMDX 按维度排序
【发布时间】:2016-06-21 12:45:17
【问题描述】:

在 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

从 MDX 排序我们有降序

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

上升

1 月日期不在这两种排序的顶部,这表明我按 FactSubmission.ID 键而不是 DimTime.CalendarYearMonth 进行排序

事情是这样运作的吗?我想把 1 月、2 月、3 月拉回来。

DimTime.CalendarYearMonthNum 是一列,其数据格式为 201501,201502,201503 等。这里尝试使用此列对 CalendarYearMonth 数据进行排序。

调试查询以选择键

非空查询

【问题讨论】:

  • 它似乎是在排序字符串,这将导致这样的输出取决于ASC / DESC 顺序。也许您可以将值更改为月数,例如:2016-01 ...
  • @ConsiderMe 我有点明白你在说什么。如果我将第一个和第二个 ORDER 参数切换为严格的数值,则排序按预期工作。有没有办法选择字符串版本,并按对应的数值排序?

标签: sorting mdx pentaho


【解决方案1】:

尝试使用不同的属性进行排序:

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_VALUE:http://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];

【讨论】:

  • 非常感谢您回复我所有的 MDX 问题,查看此处记录的内在属性 (diethardsteiner.github.io/olap/2015/02/27/…),MEMBER_VALUE 可能与 MEMBER_KEY 相同? MEMBER_VALUE 看起来不是我至少可以使用的属性。考虑我对字符串与数字排序的问题有很好的评论,但它似乎不想让我从与我选择的集合不同的列中排序。
  • @AndrewWalters 看起来 MEMBER_VALUE 没有在 Modrian 中实现。试试.Value吧。
  • 看起来使用 [DimTime.CalendarYearMonth].CurrentMember.Value 作为第二个参数排序与使用 MEMBER_KEY 属性相同
  • @AndrewWalters 以及使用参数DESC 你试过BDESC 吗?我很想知道您在多维数据集中为CalendarYearMonth 使用了哪些值。
  • Bdesc、Basc 的行为方式相同。值应该在问题的顶部(sql 选择)。如果这不是您要找的东西,请告诉我。
【解决方案2】:

您正在按字母顺序排序。 February->January->March.

为了根据月份数进行排序,需要有一个映射一月 1 日、二月 2 日、三月 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]

为安德鲁编辑

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

【讨论】:

  • 我有另一个字段,CalendaryearMonthNum,它看起来像 201501、201502、201503 等。我将如何使用该字段对 CalendarYearMonth 值进行排序?
  • 完美!请使用该字段。
  • 你能看看我的语法吗?我已经在底部更新了原始问题。
  • 在 with 语句中,Measures.foo 应该是什么?
  • @SouravA 而不是将NonEmpty 与度量一起使用,因为[CalendarMonthNum] 和[CalendarYearMonth] 是同一维度中的两个层次结构,您可以使用EXISTS 函数而不是NonEmpty:它应该很好用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多