powerbi - 按列计算持续时间
问题描述
我有一个包含五列(就诊日期、医生、患者 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
)
解决方案
我添加了一个新的计算列“访问结束”:
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)
推荐阅读
- kotlin - 保留有关失败项目处理的详细信息
- laravel - Laravel - 在中间件中更改路线
- reactjs - TypeError:未定义不是一个对象(评估'navigation.route.params')
- firebase - 如果用户登录或未登录,则无法更新页面。扑火
- meteor - 如何在 BigBlueButton html5-client 中进行 HTML 更改或自定义模块(如 poll)?
- php - 用一列中的值链接的 MySQL 表数据构建多维 PHP 数组
- python - Python中的时间戳、时间增量和转换
- channel - 检查下一个流通道是否为空
- javascript - 是否可以从 react-native 中的类组件访问功能上下文?
- jquery - onchange 类别下拉列表显示功能帖子和博客列表