let
源 = Excel.CurrentWorkbook(){[Name="表2"]}[Content],
自定义1 = Table.FromRows(List.Combine(List.Transform(Table.ToRows(源),each [a=List.RemoveNulls(_),b=List.Count(a),c=List.Zip({List.Repeat(List.FirstN(a,1),b-1),List.Skip(a,1)})][c])),{"姓名","时间"}),
自定义2 = Table.Group(自定义1,"姓名",{"分组",each [a=Table.ToColumns(_),b=List.Transform(a{1},Number.From),c={1}&List.Transform(List.Zip({List.Skip(b),List.RemoveLastN(b,1)}),(x)=>x{0}-x{1}),d=Table.FromColumns(a&{c},{"姓名","时间","标识"}),e=Table.Group(d,"标识",{"分组",each {_[姓名]{0},List.Min(_[时间]),List.Max(_[时间])}},0,(x,y)=>Number.From(y<>1))][e][分组]}),
自定义3 = Table.FromRows(List.Combine(自定义2[分组]),{"姓名","开始时间","结束时间"}),
更改的类型 = Table.TransformColumnTypes(自定义3,{{"开始时间", type date}, {"结束时间", type date}})
in
更改的类型
|