4

我有一个具有以下三个维度的多维数据集:日期、时间和班次。我有一个名为 [Pieces Succeeded] 的度量,我想要一个 Shift 小时的 [Pieces Succeeded] 的运行总数。班次可以跨越一天以上,因此在以下查询中,我对日期和时间维度进行了交叉连接。

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

我将如何让总和在交叉连接集上工作,以便运行总计可以跨天工作?

谢谢

4

1 回答 1

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]
于 2012-04-10T19:26:52.423 回答