在脚本中:
使用下面的脚本将向Process
表中添加一个新字段 - NetWorkingDays
。此字段将包含每个项目的工作日 ( Id
)。在数据集中使用此字段将更容易计算 UI 中的平均值(类似于sum(NetWorkingDays) / count(distinct Id)
Process:
Load * Inline [
Id, Name , CretedOn
1, Process1, 2019-04-02
2, Process2, 2019-04-05
3, Process3, 2019-05-02
4, Process4, 2019-06-02
];
ProcessHistory:
Load
Id as ProcessHistoryId,
ProcessId as Id,
Status,
CreatedOn as ProcessHistoryCreatedOn
;
Load * Inline [
Id, ProcessId, Status , CreatedOn
1, 1, Status 1, 2019-04-02
2, 1, Status 2, 2019-04-02
3, 1, Status 3, 2019-04-04
4, 2, Status 1, 2019-04-05
5, 2, Status 3, 2019-04-06
6, 3, Status 1, 2019-05-07
7, 3, Status 3, 2019-05-09
8, 4, Status 1, 2019-06-02
9, 4, Status 2, 2019-06-04
10, 4, Status 3, 2019-06-07
];
TempTable:
Load
Id,
min(CretedOn) as MinCreatedOn
Resident
Process
Group By
Id
;
join (TempTable)
Load
Id,
max(ProcessHistoryCreatedOn) as MaxCreatedOn
Resident
ProcessHistory
Where
Status = 'Status 3'
Group By
Id
;
NetWorkingDaysData:
Load
Id,
NetWorkDays(MinCreatedOn, MaxCreatedOn) as NetWorkingDays
Resident
TempTable
;
Drop Table TempTable;
脚本的最后一部分(由内而外):
创建临时表以min(CreatedOn)
从Process
表和max(ProcessHistoryCreatedOn)
表中计算ProcessHistory
。ProcessHistory
也被过滤为仅包含其中的记录Status = 'Status 3'
(两个表都是按 聚合的Id
)
TempTable:
Load
Id,
min(CretedOn) as MinCreatedOn
Resident
Process
Group By
Id
;
join (TempTable)
Load
Id,
max(ProcessHistoryCreatedOn) as MaxCreatedOn
Resident
ProcessHistory
Where
Status = 'Status 3'
Group By
Id
;
创建临时表后,我们可以创建最终表,我们将在其中使用NetWorkDays函数计算净工作日数。该NetWorkingDaysData
表将只有两个字段 -Id
和NetWorkingDays
NetWorkingDaysData:
Load
Id,
NetWorkDays(MinCreatedOn, MaxCreatedOn) as NetWorkingDays
Resident
TempTable
;
最后一步是放弃TempTable
- 它不再需要
在用户界面中:
使用下面的表达式可以在 UI 中实现相同的结果。请记住,UI 方法可能会导致更高的资源消耗!由于所有计算都是即时的(取决于您的数据集有多大)
avg(
Aggr(
NetWorkDays( min(ProcessHistoryCreatedOn) , max( {< Status = {'Status 3'} >} ProcessHistoryCreatedOn) )
, Id)
)