DAX / PowerPivot重叠三个时间段

时间:2017-11-21 18:44:52

标签: excel datetime excel-2013 powerpivot dax

我正在尝试将事件的有效持续时间计算为计算列,例如: [事件总持续时间] - [与事件重叠的非办公时间] - [办公时间内的系统停机时间] 而且我无法弄清楚如何做到这一点

OfficeHoursTable:

date - office hours start time - office hours end time - is working day
01/01/2017 - 08:00 am - 08:00 pm - 0
02/01/2017 - 08:00 am - 08:00 pm - 1
...
09/01/2017 - 08:00 am - 08:00 pm - 1
10/01/2017 - 08:00 am - 08:00 pm - 1
11/01/2017 - 08:00 am - 08:00 pm - 1
...

SystemDowntimeTable:

date - system downtime start time - system downtime end time
01/01/2017 - 08:17 am - 9:43 am
10/01/2017 - 7:00 pm - 8:00 pm

EventsTable:

EventID - start datetime - end datetime - effective duration
1 - 01/01/2017 7:40 am - 01/01/2017 8:40 am - 0; Comment: 0 is because though there was a dowtime of the system overlapping this event, the event itself was during non working day
2 - 09/01/2017 7:40 am - 11/01/2017 11:00 am - 24; Comment: [total duration of event] - [out of office hours overlapping the event] - [system downtime during office hours] = 24 hours
3 - 

我希望此有效持续时间计算列位于EventsTable

正如你可以想象的那样,有很多重叠和时间智能正在进行中,我无法绕过这个。

我正在运行PowerPivot for Excel 2013

1 个答案:

答案 0 :(得分:1)

我也在修补这个;这是我对蛮力方法的初步看法:

  1. 制作一个主要的小时表,其中列出了您的最小值之间列出的所有小时数 数据集中的datetime和max datetime
    1. 将您的停机时间加入到该表中,将每小时标记为" up" /" down"
    2. 将您的办公时间加入主要时间表,将每个人标记为"工作" /"离开办公室"
    3. 在小时表中创建一个计算列valid_hours,如果" up"&" working"否则0
    4. 对于每个事件,您可以在表格的DAX中执行列公式:
  2. in_scope_event_hours = CALCULATE(SUM(hours_table [valid_hours]),FILTER(hours_table,hours_table [datetime]> = event [start]&& hours_table [datetime]< = event [end]))