// Table3
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
Unpivoted = Table.UnpivotOtherColumns(Source, {"Site ID"}, "Атрибут", "Значение"),
Grouped = Table.Group(Unpivoted, {"Site ID"}, {{"tab", each Table.Sort(_, {"Атрибут"}), type table}}),
AddedMSOnly = Table.AddColumn(Grouped, "tab_MS_only", each Table.SelectRows([tab], each not Text.Contains(_[Атрибут], "STATUS"))),
AddedLastMS = Table.AddColumn(AddedMSOnly, "Last MS", each List.Last([tab_MS_only][Атрибут])),
AddedLastMSDate = Table.AddColumn(AddedLastMS, "Last MS Date", each List.Last([tab_MS_only][Значение])),
AddedLastStatus = Table.AddColumn(AddedLastMSDate, "Status", each if Text.Contains(List.Last([tab][Атрибут]), "STATUS") then List.Last([tab][Значение]) else null),
Removed = Table.SelectColumns(AddedLastStatus,{"Site ID", "Last MS", "Last MS Date", "Status"}),
Merged = Table.NestedJoin(Source,{"Site ID"},Removed,{"Site ID"},"Removed",JoinKind.LeftOuter),
Expanded = Table.ExpandTableColumn(Merged, "Removed", {"Last MS", "Last MS Date", "Status"}, {"Last MS", "Last MS Date", "Status"}),
Replaced = Table.ReplaceValue(Expanded,null,"no progress",Replacer.ReplaceValue,{"Last MS"}),
MStoDate = List.Select(List.Skip(Table.ColumnNames(Source),1), each not Text.Contains(_, "STATUS")) & {"Last MS Date"},
ListToTypes = List.Transform(MStoDate, each {_, type date}),
ChangedDateType = Table.TransformColumnTypes(Replaced,ListToTypes),
ChangedTextType = Table.TransformColumnTypes(ChangedDateType,{{"Site ID", type text}, {"Last MS", type text}, {"Status", type text}})
in
ChangedTextType |