根据aggr()答案返回相关字段?

时间:2016-04-20 11:01:37

标签: qlikview qliksense

所以我遇到了这个问题,我们想知道哪个机器最后开始工作。即哪台机器是最后一个注册负载的机器。所以这个

max(aggr(min({<ACTIVITY={'Loading'}>}[RECORD START TIME]),
       [CYCLE RECORD SHIFT],[CYCLE PRIMARY MACHINE])) 

给了我正确的时间,但现在我希望能够返回机器名称。

以下是数据样本

load * inline [
ACTIVITY,CYCLE PRIMARY MACHINE,CYCLE RECORD SHIFT,CYCLE SHIFT START TIME,RECORD START TIME
Loading,DT90015,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 11:45:17
Loading,DT90015,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 12:02:14
Loading,DT90015,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 12:21:32
Loading,DT90023,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 08:12:48
Loading,DT90023,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 08:50:43
Loading,DT90023,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 09:17:27
Loading,DT90023,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 09:53:19
Loading,DT90023,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 11:51:52
Loading,DT90023,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 12:07:09
Loading,DT90023,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 12:29:23
Loading,DT90024,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 08:08:54
Loading,DT90024,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 08:24:51
Loading,DT90024,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 08:40:15
Loading,DT90024,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 09:02:07
Loading,DT90024,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 09:25:59
Loading,DT90024,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 09:57:36
Loading,DT90024,2016/02/25.0,25/02/2016 07:00:00,25/02/2016 12:37:09
];

感谢Eldad的建议,但是返回了这个:

Per shift performance

我应该在原始问题中包含我想要创建的表格

2 个答案:

答案 0 :(得分:1)

创建一个新变量&#34; vMax&#34;并指定它

=Timestamp(max(aggr(min({<ACTIVITY={'Loading'}>}[RECORD START TIME]),
   [CYCLE RECORD SHIFT],[CYCLE PRIMARY MACHINE])) )

然后使用此计算来获取计算机名称:

=MaxString({<[RECORD START TIME]={'$(vMax)'}>}[CYCLE PRIMARY MACHINE])

答案 1 :(得分:1)

抱歉延误, 所以here是一个有效的解决方案, 基本上在您的脚本中,您需要创建另一个加重的表,如

LastMachine:
Load [CYCLE RECORD SHIFT], max([RECORD START TIME]) as max_ts Resident Data group by [CYCLE RECORD SHIFT];
left join
Load [CYCLE RECORD SHIFT],[RECORD START TIME] as max_ts, [CYCLE PRIMARY MACHINE] as Last_Machine Resident Data;

然后你得到

enter image description here