A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
I cannot understand why you need the last 2 columns as seen in your result table. Anyways, try this M code
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"FormalName", type text}, {"PreferredName", type text}, {"Role", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [PreferredName]=null then [FormalName] else [PreferredName]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"FormalName", "PreferredName"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"Custom"}, {{"Roles", each Text.Combine([Role], ", "), type nullable text}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Custom", Order.Ascending}})
in
#"Sorted Rows"
Hope this helps.