【问题标题】:Spotfire how to make calculation along one coloumnSpotfire如何沿一列进行计算
【发布时间】:2017-08-13 17:52:50
【问题描述】:

我有一个如下的数据表。我想创建一个名为“时差”的新列,用于捕获 [STAGE] 开始和 [STAGE] 结束之间的时间差。不使用数据转换有什么办法吗?

谢谢!

【问题讨论】:

  • 每个ID可以只有1个开始和1个结束吗?
  • 是的,你是对的

标签: calculated-columns spotfire


【解决方案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             |
+----+---------+---------+------+-----------------+

【讨论】:

  • 您好,我想我没有清楚地说明我的问题。有时每个[ID]的第一阶段不是“开始”,最后一个阶段不是“结束”,所以必须明确条件是我想在[阶段]等于开始时获得开始时间,[动作]等于批准,[stage]等于结束,[action]等于批准的结束时间。谢谢!
  • @BenWang 你能提供另一个考虑到这一点的示例数据集吗?
  • 还有 G-I 表示这两个时间点之间的时差
  • @BenWang 我不确定你最后的评论是什么意思,但我提供了另一种解决方案。
  • 您介意解释一下吗?为什么我们需要 max([Time]) 而不是 [ID] 以及为什么我们需要 min([Time]) 而不是 id?谢谢
猜你喜欢
  • 2016-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多