向所有聪明人致以今天的问候:slightly_smiling_face: 我是 powerquery 的基本用户,没有安装 powerBI。我需要你的帮助来解决我正在努力解决的这个问题。
我有一个事务列表(数千行),其中包含中断开始时间和结束时间,其中大多数跨越多个月。
数量 | 停电开始 | 停电结束 |
---|---|---|
INC2536 | 2023年1月4日4:01 | 2023年5月4日9:01 |
INC2537 | 2023年1月4日4:01 | 2023/1/4 9:01 |
INC2538 | 2/8/2023 9:46 | 2023年4月15日11:01 |
INC2539 | 2023/3/24 16:35 | 2023年5月24日20:28 |
INC2540 | 2023年5月28日16:21 | 2023年7月3日17:38 |
INC2541 | 2023年6月4日8:25 | 2023年6月4日9:42 |
INC2542 | 2023年6月17日9:25 | 2023年6月17日13:00 |
INC2543 | 2023年6月17日9:25 | 2023年6月18日11:33 |
INC2544 | 2023年6月17日9:25 | 2023年7月18日11:33 |
我需要计算某个月份(例如 4 月 23 日)内的事件计数和停机时间总和。换句话说,如果我将数据透视表过滤到 23 年 4 月,它应该只提供 23 年 4 月期间某些时间的事件的计数和总和。 提前非常感谢
这样的事情会生成一个可以过滤的表格,等等
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Number", type text}, {"Outage Began", type datetime}, {"Outage Ended", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Number"}, {{"data", each
let a= _,
days=Duration.Days(a[Outage Ended]{0}-a[Outage Began]{0})+1,
#"Added Custom" = Table.AddColumn(a, "Custom", each List.Dates(Date.From([Outage Began]), days, #duration(1, 0, 0, 0))),
d= {Duration.Minutes(a[Outage Ended]{0}-a[Outage Began]{0})/60},
b = {Duration.TotalMinutes(#time(23, 59, 59)-Time.From(a[Outage Began]{0}))/60},
c={Duration.TotalMinutes(Time.From(a[Outage Ended]{0})-#time(0,0,0))/60},
Times=if days=1 then d else if days=2 then b&c else b&List.Repeat({24},days-2)&c,
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in Table.FromColumns(Table.ToColumns(#"Expanded Custom")&{Times},Table.ColumnNames(Source)&{"Date","Hours"}), type table [Number=nullable text, Outage Began=nullable datetime, Outage Ended=nullable datetime, Date=nullable date, Hours=nullable number]}}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"Outage Began", "Outage Ended", "Date", "Hours"}, {"Outage Began", "Outage Ended", "Date", "Hours"}),
#"Added Custom" = Table.AddColumn(#"Expanded data", "Month", each Date.Month([Date])),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Year", each Date.Year([Date]))
in #"Added Custom1"