【发布时间】:2018-07-12 21:53:52
【问题描述】:
我有一个大型车辆清单中发生的事件,这些事件会影响它们是在服务还是停止服务。我想根据此表中的事件创建一个能够在任何时间点计算各种库存中的车辆数量的度量。
此表从 SQL 数据库中提取到 Excel 2016 工作表中,我正在使用 PowerPivot 尝试提出 DAX 度量。
这里是一些示例数据event_list:
vehicle_id event_date event event_sequence inventory
100 2018-01-01 purchase 1 in-service
101 2018-01-01 purchase 1 in-service
102 2018-02-04 purchase 1 in-service
100 2018-02-07 maintenance 2 out-of-service
101 2018-02-14 damage 2 out-of-service
101 2018-02-18 repaired 3 in-service
100 2018-03-15 repaired 3 in-service
102 2018-05-01 damage 2 out-of-service
103 2018-06-03 purchase 1 in-service
我希望能够在 Excel 中创建一个数据透视表(或使用 CUBE 函数等)来获得这样的输出表:
date in-service out-of-service
2018-02-04 3 0
2018-02-14 1 2
2018-03-15 3 0
2018-06-03 3 1
基本上,我希望能够根据任何时间日期计算库存。该示例只有几个日期,但希望提供足够的图片。
到目前为止,我基本上已经想到了这个,但它计算的车辆数量超过了预期 - 我无法弄清楚如何只获取最新的 event_sequence 或 event_date 并使用它来计算库存。
cumulative_vehicles_at_date:=CALCULATE(
COUNTA([vehicle_id]),
IF(IF(HASONEVALUE (event_list[event_date]), VALUES (event_list[event_date]))>=event_list[event_date],event_list[event_date])
)
我尝试使用 MAX() 和 EARLIER() 函数,但它们似乎不起作用。
编辑:添加了 PowerBI 标签,因为我现在正在使用该软件来尝试解决这个问题。请参阅关于 Alexis Olson 的答案的 cmets。
【问题讨论】:
标签: ssas powerbi dax powerpivot excel-2016