|
这样写出来看上去肯定是繁琐些,但性能几乎是恒定的,不管时间间隔是1天还是10年,也不存在什么stack溢出的情况。
- // DIV
- let
- Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WerFhu5KOkoGBFRjVGVhAGEqxOtFKT3duBslBheoMDZDlNm8AysGE6gwNkeU2TAPJGcLkjDDMhAnVGZpgmmkCkzPFNNMUJmeOqc8cJmeJaR9UqM7I2MrUEoiUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [时段 = _t, 起止时间 = _t]),
- #"Changed Type" = Table.TransformColumnTypes(Source,{{"时段", type text}, {"起止时间", type text}}),
- Periods = Table.TransformColumns(
- #"Changed Type",
- {"起止时间", each let l=List.Transform(Text.Split(_,"~"), Time.From), dur=Number.Round(Duration.TotalMinutes(l{1}-l{0})) in List.Transform({0..dur-1}, each l{0}+#duration(0,0,_,0))}
- ),
- Grouped = Table.Group(Periods, "时段", {"grp", each List.Combine([起止时间])}),
- #"To Records" = Table.ToRecords(Grouped)
- in
- #"To Records"
- // elec
- let
- Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZYzBDcAgDMRWQXkjkUtIgayCsv8aQOmvT1uW56RRpAhLTc2lUd6slx9Hp8inUL5K1K3vBlzwi45BTWAXez/4xhhuRhEL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start DT" = _t, #"End DT" = _t]),
- #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start DT", type datetime}, {"End DT", type datetime}}),
- #"Added whole day" = Table.AddColumn(
- #"Changed Type",
- "whole",
- each let
- d=Duration.TotalDays(Date.From([End DT])-Date.From([Start DT]))-1
- in List.Transform(DIV, each Record.TransformFields(_, {"grp", each d*List.Count(_)}))
- ),
- #"Added Stt" = Table.AddColumn(
- #"Added whole day",
- "Stt",
- each let
- stt=Time.From([Start DT]),
- dur=Number.Round(Duration.TotalMinutes(#time(23,59,59)-stt)),
- l=List.Transform({0..dur-1}, each stt+#duration(0,0,_,0))
- in List.Transform(DIV, each Record.TransformFields(_, {"grp", each List.Count(List.Intersect({l,_}))})), type list
- ),
- #"Added End" = Table.AddColumn(
- #"Added Stt",
- "End",
- each let
- end=Time.From([End DT]),
- dur=Number.Round(Duration.TotalMinutes(end-#time(0,0,0))),
- l=List.Transform({0..dur-1}, each end-#duration(0,0,_,0))
- in List.Transform(DIV, each Record.TransformFields(_, {"grp", each List.Count(List.Intersect({l,_}))})), type list
- ),
- #"Combined Columns" = Table.CombineColumns(#"Added End", {"whole","Stt","End"}, each let t=Table.FromRecords(List.Combine(_)) in Table.Pivot(t, List.Distinct(t[时段]), "时段", "grp", List.Sum), "comb"),
- #"Expanded comb" = Table.ExpandTableColumn(#"Combined Columns", "comb", {"谷", "平", "峰", "尖"})
- in
- #"Expanded comb"
复制代码
|
评分
-
1
查看全部评分
-
|