我有一个包含五列的表格(访问日期,医生,患者ID,开始时间), 我想添加一个新列“ Duration”,此列将计算每次访问的持续时间。 我尝试对每次访问日期和医生的时间进行排名,但无法减去两行之间的时间。
| visit date | Doctor | P id | Time |
|------------+----------+--------+----------|
| 2018-08-02 | Doctor 1 | 10 | 05:10:00 |
|------------+----------+--------+----------|
| 2018-08-01 | Doctor 2 | 12 | 12:20:00 |
|------------+----------+--------+----------|
| 2018-08-03 | Doctor 1 | 07 | 06:30:00 |
|------------+----------+--------+----------|
| 2018-08-01 | Doctor 1 | 55 | 05:40:00 |
|------------+----------+--------+----------|
| 2018-08-01 | Doctor 2 | 60 | 02:50:00 |
|------------+----------+--------+----------|
| 2018-08-02 | Doctor 1 | 17 | 10:10:00 |
|------------+----------+--------+----------|
| 2018-08-02 | Doctor 1 | 20 | 13:00:00 |
|------------+----------+--------+----------|
| 2018-08-01 | Doctor 2 | 19 | 20:10:00 |
|------------+----------+--------+----------|
| 2018-08-03 | Doctor 1 | 60 | 02:20:00 |
|------------+----------+--------+----------|
| 2018-08-03 | Doctor 1 | 11 | 13:30:00 |
我创建的排名列:
Rank =
RANKX(
FILTER(
FILTER(
'test 2',
'test 2'[Doctor]=EARLIER('test 2'[Doctor])
),
'test 2'[Visit Date]=EARLIER('test 2'[Visit Date])
),
'test 2'[Time],
,
ASC,
Dense
)
答案 0 :(得分:0)
我添加了一个新的计算列“ Visit End”:
Visit End =
LOOKUPVALUE(
'test 2'[time],
'test 2'[Visit Date],
'test 2'[Visit Date],
'test 2'[Doctor],
'test 2'[Doctor],
'test 2'[Rank],
'test 2'[Rank]+1
)
添加此新列后,很容易计算持续时间,新的“ Duration”列将如下所示:
Duration = DATEDIFF('test 2'[time],'test 2'[Visit End],MINUTE)