我有一个具有以下三个维度的立方体:日期,时间和班次。我有一个称为[Pieces Succeeded]的度量,我希望按小时计算[Pieces Succeeded]的总计为Shift。 Shift可以跨越一天以上,因此在下面的查询中,我会对日期和时间维度进行交叉连接。
with
member [Measures].[Pieces Succeeded Running Total] as
sum([Time].[Hierarchy].[Hour].FirstMember:[Time].[Hour].CurrentMember, [Measures].[Pieces Succeeded])
select
{ [Measures].[Pieces Succeeded], [Measures].[Pieces Succeeded Running Total] } on columns,
nonempty(crossjoin([Date].[Month Hierarchy].[Day].Members, [Time].[Hierarchy].[Hour].Members)) on rows
from
[OEE]
where
[Shift].[Month Hierarchy].[Shift].&[501]
其中给出了以下结果:
Date Hour Pieces Succeeded Pieces Succeeded Running Total
03 Apr 2011 22 6393 6393
03 Apr 2011 23 6424 12817
04 Apr 2011 00 3816 3816
04 Apr 2011 01 5510 9326
04 Apr 2011 02 2090 11416
04 Apr 2011 03 7489 18905
04 Apr 2011 04 7307 26212
04 Apr 2011 05 5706 31918
我如何才能将总和用于交叉连接集,以便“运行总计”在几天内有效?
由于
答案 0 :(得分:3)
我整天都在这上面,最后想出来了。我认为这可能对其他人有价值,所以这是解决方案:
with
set DateHours as
nonempty(crossjoin([Date].[Month Hierarchy].[Day].Members, [Time].[Hierarchy].[Hour].Members), [Measures].[Pieces Succeeded])
member [Measures].[Rank] as
rank(([Date].[Month Hierarchy].CurrentMember, [Time].[Hierarchy].CurrentMember ), DateHours)
member [Measures].[Running Pieces Succeeded] as
iif([Measures].[Rank] = 1, [Measures].[Pieces Succeeded], sum(head(DateHours, [Measures].[rank]), [Measures].[Pieces Succeeded]))
select
{ [Measures].[Pieces Succeeded], [Measures].[Running Pieces Succeeded] } on columns,
non empty { DateHours } on rows
from
[OEE]
where
[Shift].[Month Hierarchy].[Shift].&[501]