Spotfire如何沿着一个coloumn进行计算

时间:2017-03-21 20:40:23

标签: calculated-columns spotfire

我有一个数据表如下。我想创建一个名为“Time Difference”的新列,它捕获[STAGE] start和[STAGE] end之间的时差。有没有办法不使用数据转换呢?

谢谢!

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

假设每个ID都是唯一的,并且您的数据按Time排序,其中Stage = Start是每个ID的第一行,Stage = End是最后一行每个ID的行,你可以使用:

Concatenate(Min([Time]) OVER ([ID]),"-",Max([Time]) over ([ID]))

<强>结果

+----+---------+---------+------+-----------------+
| ID |  Stage  | Action  | Time | Time Difference |
+----+---------+---------+------+-----------------+
|  1 | Start   | approve | A    | A-F             |
|  1 | Process | approve | B    | A-F             |
|  1 | Process | approve | C    | A-F             |
|  1 | Process | approve | D    | A-F             |
|  1 | Process | decline | E    | A-F             |
|  1 | End     | approve | F    | A-F             |
|  2 | Start   | approve | G    | G-I             |
|  2 | Process | decline | H    | G-I             |
|  2 | End     | approve | I    | G-I             |
+----+---------+---------+------+-----------------+

如果您的数据尚未排序,则只需应用Rank()即可解决此问题。如果是这种情况,请告诉我。

  

使用新数据进行编辑

<强>表达

Concatenate(Min(If((Upper([Stage])="START") and (Upper([Action])="APPROVE"),Max([Time]) OVER ([ID]))) OVER ([ID]),"-",Min(If((Upper([Stage])="END") and (Upper([Action])="APPROVE"),Max([Time]) OVER ([ID]))) OVER ([ID]))

<强>简化

Concatenate(Min(If((Upper([Stage])="START") and (Upper([Action])="APPROVE"),[Time])) OVER ([ID]),"-",Min(If((Upper([Stage])="END") and (Upper([Action])="APPROVE"),[Time])) OVER ([ID]))

<强>结果

+----+---------+---------+------+-----------------+
| ID |  Stage  | Action  | Time | Time Difference |
+----+---------+---------+------+-----------------+
|  1 | On hold | decline | A    | C-H             |
|  1 | Start   | decline | B    | C-H             |
|  1 | Start   | approve | C    | C-H             |
|  1 | Process | DECLINE | D    | C-H             |
|  1 | Process | approve | E    | C-H             |
|  1 | Process | approve | F    | C-H             |
|  1 | End     | decline | G    | C-H             |
|  1 | End     | approve | H    | C-H             |
|  2 | Start   | approve | I    | I-K             |
|  2 | Process | decline | J    | I-K             |
|  2 | End     | approve | K    | I-K             |
+----+---------+---------+------+-----------------+