Forum Discussion
Transpose/Transform Multiple Rows into Single Row
- 8 years ago
Well it took a short 2 hour Saturday road trip for me to come up with the realization/solution.
You're absolutely correct, Why do you need to "merge [Manager] & [Email] then splitting them"?. This is exactly what I was thinking too.
Basically, I did not think to Table.Group( ) by more than one field.
To bring closure to the question, sample data provided below:
ManagerName Email DeptID DeptDesc Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10002 Daffy2Acct Duck,Daffy [email protected] D10002 Daffy2Acct Duck,Daffy [email protected] D10002 Daffy2Acct Mouse,Minnie [email protected] D90001 Minnie1Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30003 Mickey3Acct McDuck,Scrooge [email protected] D60001 Scrouge1Acct let Source = Excel.CurrentWorkbook(){[Name="MergeTable"]}[Content], #"Removed Duplicates" = Table.Distinct(Source), #"Changed Type" = Table.TransformColumnTypes(#"Removed Duplicates",{{"ManagerName", type text}, {"Email", type text}, {"DeptID", type text}, {"DeptDesc", type text}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "ManagerName", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"LastName", "FirstName"}), #"Merged Columns" = Table.CombineColumns(#"Split Column by Delimiter",{"FirstName", "LastName"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"ManagerName"), #"Merged Columns1" = Table.CombineColumns(#"Merged Columns",{"DeptID", "DeptDesc"},Combiner.CombineTextByDelimiter(" - ", QuoteStyle.None),"DeptInfo"), // Function that adds an incrementing index number AddRanking = (table, column, newColumn) => Table.AddIndexColumn(Table.Sort(table, {{column, Order.Ascending}}), newColumn, 1, 1), #"Grouped Rows" = Table.Group(#"Merged Columns1", {"ManagerName", "Email"}, {{"Data", each _, type table}}), Transformed = Table.TransformColumns(#"Grouped Rows", {{"Data", each AddRanking(_, "DeptInfo", "Rank")}}), #"Expand Data" = Table.ExpandTableColumn(Transformed, "Data", {"DeptInfo", "Rank"}, {"DeptInfo", "Rank"}), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expand Data", {{"Rank", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expand Data", {{"Rank", type text}}, "en-US")[Rank]), "Rank", "DeptInfo") in #"Pivoted Column"Expected Table results for an MSWord Email Merge where each manager gets one email with a list of their department's.
ManagerName Email 1 2 3 Daffy Duck [email protected] D10001 - Daffy1Acct D10002 - Daffy2Acct Mickey Mouse [email protected] D30001 - Mickey1Acct D30002 - Mickey2Acct D30003 - Mickey3Acct Minnie Mouse [email protected] D90001 - Minnie1Acct D90002 - Minnie2Acct Scrooge McDuck [email protected] D60001 - Scrouge1Acct
Hi ChrisMendoza,
Why do you need to "merge [Manager] & [Email] then splitting them"? Please show us the original table data.
Regards,
Yuliana Gu
- ChrisMendoza8 years ago
Resident Rockstar
Well it took a short 2 hour Saturday road trip for me to come up with the realization/solution.
You're absolutely correct, Why do you need to "merge [Manager] & [Email] then splitting them"?. This is exactly what I was thinking too.
Basically, I did not think to Table.Group( ) by more than one field.
To bring closure to the question, sample data provided below:
ManagerName Email DeptID DeptDesc Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10001 Daffy1Acct Duck,Daffy [email protected] D10002 Daffy2Acct Duck,Daffy [email protected] D10002 Daffy2Acct Duck,Daffy [email protected] D10002 Daffy2Acct Mouse,Minnie [email protected] D90001 Minnie1Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Minnie [email protected] D90002 Minnie2Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30001 Mickey1Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30002 Mickey2Acct Mouse,Mickey [email protected] D30003 Mickey3Acct McDuck,Scrooge [email protected] D60001 Scrouge1Acct let Source = Excel.CurrentWorkbook(){[Name="MergeTable"]}[Content], #"Removed Duplicates" = Table.Distinct(Source), #"Changed Type" = Table.TransformColumnTypes(#"Removed Duplicates",{{"ManagerName", type text}, {"Email", type text}, {"DeptID", type text}, {"DeptDesc", type text}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "ManagerName", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"LastName", "FirstName"}), #"Merged Columns" = Table.CombineColumns(#"Split Column by Delimiter",{"FirstName", "LastName"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"ManagerName"), #"Merged Columns1" = Table.CombineColumns(#"Merged Columns",{"DeptID", "DeptDesc"},Combiner.CombineTextByDelimiter(" - ", QuoteStyle.None),"DeptInfo"), // Function that adds an incrementing index number AddRanking = (table, column, newColumn) => Table.AddIndexColumn(Table.Sort(table, {{column, Order.Ascending}}), newColumn, 1, 1), #"Grouped Rows" = Table.Group(#"Merged Columns1", {"ManagerName", "Email"}, {{"Data", each _, type table}}), Transformed = Table.TransformColumns(#"Grouped Rows", {{"Data", each AddRanking(_, "DeptInfo", "Rank")}}), #"Expand Data" = Table.ExpandTableColumn(Transformed, "Data", {"DeptInfo", "Rank"}, {"DeptInfo", "Rank"}), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expand Data", {{"Rank", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expand Data", {{"Rank", type text}}, "en-US")[Rank]), "Rank", "DeptInfo") in #"Pivoted Column"Expected Table results for an MSWord Email Merge where each manager gets one email with a list of their department's.
ManagerName Email 1 2 3 Daffy Duck [email protected] D10001 - Daffy1Acct D10002 - Daffy2Acct Mickey Mouse [email protected] D30001 - Mickey1Acct D30002 - Mickey2Acct D30003 - Mickey3Acct Minnie Mouse [email protected] D90001 - Minnie1Acct D90002 - Minnie2Acct Scrooge McDuck [email protected] D60001 - Scrouge1Acct