首页 > 解决方案 > 按列计算持续时间

问题描述

我有一个包含五列(就诊日期、医生、患者 ID、开始时间)的表,我想添加一个新列“持续时间”,该列将计算每次就诊的持续时间。我试图对每次就诊日期和医生的时间进行排名,但我无法减去行之间的时间。

| 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
)

标签: powerbidax

解决方案


我添加了一个新的计算列“访问结束”:

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 = DATEDIFF('test 2'[time],'test 2'[Visit End],MINUTE)

推荐阅读