我有一个具有以下尺寸的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.
?
答案 0 :(得分:1)
如果您查看屏幕截图,Time.DayName级别中的日期按自然顺序排序:它是成员名称的字母顺序。
SSAS无法确定&#34;知道&#34;你想要的订单是什么。我建议在此维度中添加一个Key列,按照您想要的顺序对天数进行编号,并将维度属性的OrderBy属性更改为Key而不是Name。 (也许你已经有了一个密钥:但是OrderBy = Name自然会按照他们的名字命令成员)。
添加: SSAS中有一个维度属性Type属性,可以设置为&#34;星期几&#34; - 但我从未使用它,也不知道它是否能正确检测到你的会员名称是工作日的名字。或者它是否会在&#34;右边#34;你想要开始一周的那一天。您可以尝试设置并查看会发生什么。
答案 1 :(得分: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];
答案 2 :(得分: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]