let
Source = Excel.CurrentWorkbook(){[Name=”Fruits”]}[Content],
#”Changed Type” = Table.TransformColumnTypes(Source,{{“FruitId”, Int64.Type}, {“FruitName”, type text}}),
#”Grouped Rows” = Table.Group(#”Changed Type”, {“FruitId”}, {{“Count”, each _, type table [FruitId=nullable number, FruitName=nullable text]}}),
#”Added Custom” = Table.AddColumn(#”Grouped Rows”, “Custom”, each Table.AddIndexColumn([Count], “Index”, 1)),
#”Removed Other Columns” = Table.SelectColumns(#”Added Custom”,{“Custom”}),
#”Expanded Custom” = Table.ExpandTableColumn(#”Removed Other Columns”, “Custom”, {“FruitId”, “FruitName”, “Index”}, {“FruitId”, “FruitName”, “Index”}),
#”Pivoted Column” = Table.Pivot(Table.TransformColumnTypes(#”Expanded Custom”, {{“Index”, type text}}, “cs-CZ”), List.Distinct(Table.TransformColumnTypes(#”Expanded Custom”, {{“Index”, type text}}, “cs-CZ”)[Index]), “Index”, “FruitName”),
#”Inserted Merged Column” = Table.AddColumn(#”Pivoted Column”, “Merged”, each Text.Combine(List.Transform(Record.FieldValues(_), Text.From), “,”), type text),
#”Removed Other Columns1″ = Table.SelectColumns(#”Inserted Merged Column”,{“Merged”}),
#”Split Column by Delimiter” = Table.SplitColumn(#”Removed Other Columns1″, “Merged”, Splitter.SplitTextByEachDelimiter({“,”}, QuoteStyle.Csv, false), {“Merged.1”, “Merged.2”}),
#”Changed Type1″ = Table.TransformColumnTypes(#”Split Column by Delimiter”,{{“Merged.1”, Int64.Type}, {“Merged.2”, type text}}),
#”Renamed Columns” = Table.RenameColumns(#”Changed Type1″,{{“Merged.1”, “FruitId”}, {“Merged.2”, “FruitName”}})
in
#”Renamed Columns”