Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi, I need to transform data as per example below:
Table is:
+----+------+ | Id | Name | +----+------+ | 1 | aaa | | 1 | bbb | | 1 | ccc | | 1 | ddd | | 1 | eee | +----+------+
Required output:
+----+---------------------+ | Id | abc | +----+---------------------+ | 1 | aaa,bbb,ccc,ddd,eee | +----+---------------------+
How can I achieve this in power query?
Thank you in advance
Solved! Go to Solution.
Full M query (my data came from an Excel table which explains the source)
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Name", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Id"}, {{"AllRows", each _, type table [Id=number, Name=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Names", each Table.Column([AllRows], "Name")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Names", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Removed Other Columns" = Table.SelectColumns(#"Extracted Values",{"Id", "Names"})
in
#"Removed Other Columns"
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingHello @bbbt123
didn't see that @edhans did already answer. As i've put down already a solution, i will post it. It uses a little leaner way.
let
Source = #table
(
{"ID","Name"},
{
{"1","aaa"}, {"1","bbb"}, {"1","ccc"}, {"1","ddd"}, {"1","eee"}
}
),
Group = Table.Group(Source, {"ID"}, {{"Combine", each Text.Combine(_[Name], ", "), type text}})
in
Group
Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Full M query (my data came from an Excel table which explains the source)
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Name", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Id"}, {{"AllRows", each _, type table [Id=number, Name=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Names", each Table.Column([AllRows], "Name")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Names", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Removed Other Columns" = Table.SelectColumns(#"Extracted Values",{"Id", "Names"})
in
#"Removed Other Columns"
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingThank you 😄