let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
NgayGio = List.RemoveNulls(Record.ToList(Source{0})),
ColName = List.Distinct(Record.ToList(Source{1})),
ToFrom = List.Transform(List.Split(Table.ToColumns(Table.Skip(Source,2)),List.Count(ColName)), each Table.FromColumns(_,ColName)),
Custom2 = Table.FromColumns({NgayGio} & {ToFrom}),
#"Changed Type" = Table.TransformColumnTypes(Custom2,{{"Column1", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each "SMT"),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Column1", "Custom", "Column2"}),
#"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Column1", "Date"}, {"Custom", "Dept"}}),
#"Expanded Column2" = Table.ExpandTableColumn(#"Renamed Columns", "Column2", {"Line", "MO", "Qty"}, {"Line", "MO", "Qty"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Column2", each ([Line] <> null))
in
#"Filtered Rows"
Cảm ơn bác rất nhiều ạ, trông code ngắn gọn quáTham khảo code trong file đính kèm:
nhấn vào mũi tên để có được kết quả
Em cảm ơn bác nhiều ạĐây là M code của Power query
Mã:let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], NgayGio = List.RemoveNulls(Record.ToList(Source{0})), ColName = List.Distinct(Record.ToList(Source{1})), ToFrom = List.Transform(List.Split(Table.ToColumns(Table.Skip(Source,2)),List.Count(ColName)), each Table.FromColumns(_,ColName)), Custom2 = Table.FromColumns({NgayGio} & {ToFrom}), #"Changed Type" = Table.TransformColumnTypes(Custom2,{{"Column1", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each "SMT"), #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Column1", "Custom", "Column2"}), #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Column1", "Date"}, {"Custom", "Dept"}}), #"Expanded Column2" = Table.ExpandTableColumn(#"Renamed Columns", "Column2", {"Line", "MO", "Qty"}, {"Line", "MO", "Qty"}), #"Filtered Rows" = Table.SelectRows(#"Expanded Column2", each ([Line] <> null)) in #"Filtered Rows"