我对评论中的未解决问题做了以下假设:
- 放大时不应更改特定范围的总和。
- 07/2011 的前一个值为 0(与 06/2011 的值相同)
因此,必须根据周对所有值进行计算。可能这可以通过集合分析来完成,但我想这些比较和查找即使不是不可能也很困难。
我更喜欢预先计算加载脚本中的值的解决方案:
BaseData:
Load
oWeek,
value,
left(oWeek,2) as nWeek,
right(oWeek,4) as nYear,
MakeWeekDate(right(oWeek,4), left(oWeek,2)) as weekstart
inline
[
oWeek, value
01/2011, 256
02/2011, 2056
03/2011, 112
04/2011, 95
05/2011, 1069
07/2011, 125
08/2011, 73
];
首先计算所有需要的周的开始时间:
TEMP_1:
Load
oWeek, value, nWeek, nYear, weekstart,
WeekStart(weekstart, -1) as weekstart_p1,
WeekStart(weekstart, -2) as weekstart_p2,
WeekStart(weekstart, 1) as weekstart_n1,
WeekStart(weekstart, 2) as weekstart_n2
resident BaseData;
drop Table BaseData;
查找周的值:
TEMP_2:
Load
oWeek, value, nWeek, nYear, weekstart,
weekstart_p1, weekstart_p2, weekstart_n1, weekstart_n2,
lookup('value', 'weekstart', weekstart_p1, 'TEMP_1') as value_p1,
lookup('value', 'weekstart', weekstart_p2, 'TEMP_1') as value_p2,
lookup('value', 'weekstart', weekstart_n1, 'TEMP_1') as value_n1,
lookup('value', 'weekstart', weekstart_n2, 'TEMP_1') as value_n2
resident TEMP_1;
drop Table TEMP_1;
字段 value_p1 ... 可能包含“null”,因此必须将它们转换为 0。
TEMP_3:
Load
oWeek, value, nWeek, nYear, weekstart,
weekstart_p1, weekstart_p2, weekstart_n1, weekstart_n2,
value_p1, value_p2, value_n1, value_n2,
if (isnull(value_p2), 0, value_p2) as val_p2,
if (isnull(value_p1), 0, value_p1) as val_p1,
if (isnull(value_n1), 0, value_n1) as val_n1,
if (isnull(value_n2), 0, value_n2) as val_n2
resident TEMP_2;
drop Table TEMP_2;
字段 val_p1 现在包含有效的数值。
Data:
Load
oWeek, value, nWeek, nYear, weekstart,
weekstart_p1, weekstart_p2, weekstart_n1, weekstart_n2,
val_p1, val_p2, val_n1, val_n2,
val_p2 + val_p1 + value + val_n1 + val_n2 as mySum
resident TEMP_3;
drop Table TEMP_3;
在我的仪表板中,我有一个表格框:
还有一张图:
希望有帮助。