0

我有一个具有以下尺寸的 SSAS 多维数据集:

Time
    DayName <- Hierarchy

Item
    Description <- Hierarchy

Measures维度中,我有一个度量LostAmount

我想查询多维数据集,以便获得每周损失金额的总和。以下查询有效:

select
    except(Time.DayName.members, {Time.DayName.[All]}) on 0,
    except(Item.Description.members, {Item.Description.All}) on 1
from Cube

但是当返回结果时,列的顺序不是工作日的自然顺序(即列的顺序是Friday, Monday, Sunday etc)。

查询结果。

我怎样才能让结果列按工作日的自然顺序排列,即Monday, Tuesday etc.

4

3 回答 3

1

虽然更改立方体结构肯定更好,但有时这不是一个可行的选择。在这种情况下,它必须在MDX代码内部处理(速度较慢)。下面是一种方法。

WITH 
  MEMBER measures.weekdaynumber AS  
    CASE Time.DayName.CURRENTMEMBER 
        WHEN "Monday" THEN 1
        WHEN "Tuesday" THEN 2
        WHEN "Wednesday" THEN 3
        WHEN "Thursday" THEN 4
        WHEN "Friday" THEN 5
        WHEN "Saturday" THEN 6
        WHEN "Sunday" THEN 7
    END

SELECT 
  Order
  (
    Except
    (
      Time.DayName.MEMBERS
     ,{Time.DayName.[All]}
    )
   ,Measures.weekdaynumber
  ) ON 0
 ,Except
  (
    [Item].[Description].MEMBERS
   ,{[Item].[Description].[All]}
  ) ON 1
FROM [Cube];
于 2015-09-02T06:55:14.053 回答
1

If you look at your screenshot, the days in the Time.DayName level are being sorted in natural order: it's the alphabetical order of the member names.

There's no way that SSAS can "know" what the order you want is. I'd suggest adding a Key column to this dimension, numbering the days in the order you want, and changing the dimension attribute's OrderBy property to Key rather than Name. (Perhaps you already do have a key: but OrderBy=Name will naturally order the members by their name).

Addition: There is a dimension attribute Type property in SSAS, which can be set to "Day of Week" - but I've never used it, and don't know whether it would correctly detect that your member names are the names of weekdays. Or whether it will order your week starting on the "right" day that you want to start your week from. You could try setting it and seeing what happens.

于 2015-08-31T15:48:22.140 回答
0

Measures通过在维度上定义其他成员并按所需顺序输出它们,我找到了排序问题的解决方法:

with
member Measures.Monday as 
    sum(Time.DayName.&[Monday], Measures.LostValue)
member Measures.Tuesday as
    sum(Time.DayName.&[Tuesday], Measures.LostValue)
member Measures.Wednesday as
    sum(Time.DayName.&[Wednesday], Measures.LostValue)
member Measures.Thursday as 
    sum(Time.DayName.&[Thursday], Measures.LostValue)
member Measures.Friday as
    sum(Time.DayName.&[Friday], Measures.LostValue)
member Measures.Saturday as
    sum(Time.DayName.&[Saturday], Measures.LostValue)
member Measures.Sunday as
    sum(Time.DayName.&[Sunday], Measures.LostValue)
select
{
    Measures.Monday,
    Measures.Tuesday,
    Measures.Wednesday,
    Measures.Thursday,
    Measures.Friday,
    Measures.Saturday,
    Measures.Sunday
} on 0,
except(Item.Description.members, {Item.Description.[All]}) on 1
from [Cube]
于 2015-09-03T06:43:22.513 回答