2017-03-21 48 views
2

我有一個數據表,如下所示。我想創建一個名爲「Time Difference」的新列,它捕獲[STAGE]開始和[STAGE]結束之間的時間差。有沒有辦法做到這一點,而不使用數據轉換?Spotfire如何沿一個顏色計算

謝謝!

enter image description here

enter image description here

+0

可以在每個ID只能有1個起始和結束1? – scsimon

+0

是的,你是對的 –

回答

1

假設每個ID是獨一無二的,你的數據是由Time有序其中Stage = Start是第一排的每個IDStage = 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])) 

簡化EDIT

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    | 
+----+---------+---------+------+-----------------+ 
+0

嗨,我想我沒有明確說明我的問題。有時每個[ID]的第一階段不是「開始」,最後一個階段不是「結束」,所以必須具體說明條件,我希望在[階段]等於開始時獲得開始時間,[動作]等於批准,並且[階段]等於結束並且[行動]等於批准時的結束時間。謝謝! –

+0

@ BenWang您能否提供另一個考慮到這一點的樣本數據集? – scsimon

+0

是的,我剛剛編輯我的問題 –