Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
katemke
Frequent Visitor

Create Columns from Duplicate Rows

I have a table that lists a Record ID and a Name of a participant as such:

RECORD IDNAME
1Jim Smith
2Jane Johnson
3Nick Peters
4Kathy James
5Jim Smith
6Joe Doe
7Nick Peters

 

I want to transform this table to create a new table that lists individuals with all associated Record IDs, as such

NameRecord ID 1Record ID 2
Jim Smith15
Jane Johnson2null
Nick Peters37
Kathy James4null
Joe Doe6null

 

Individuals can potentially have more than 2 record IDs but it is unlikely.  Wondering how I can transform the data in Power Query to create this new table

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

this code should work also in case you have more than two recIDs by name

 

 

 

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKzFUIzs0syVCK1YlWMgKJJOalKnjlZ+QV5+eBBY2Bgn6ZydkKAaklqUXFYDEToJh3YklGpYJXYm4qRMwUwzgzkEh+qoJLfiqYb45uUiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"RECORD ID" = _t, NAME = _t]),
    #"Modificato tipo" = Table.TransformColumnTypes(Origine,{{"RECORD ID", Int64.Type}, {"NAME", type text}}),
    #"Raggruppate righe" = Table.Group(#"Modificato tipo", {"NAME"}, {{"recID", each _[RECORD ID]}}),
    #"Valori estratti" = Table.TransformColumns(#"Raggruppate righe", {"recID", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    scd = Table.SplitColumn(#"Valori estratti", "recID", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv))
in
    scd

 

 

 

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKzFUIzs0syVCK1YlWMgKJJOalKnjlZ+QV5+eBBY2Bgn6ZydkKAaklqUXFYDEToJh3YklGpYJXYm4qRMwUwzgzkEh+qoJLfiqYb47FJAs0NZYYphgbYwgZGqCbFAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"RECORD ID" = _t, NAME = _t]),
    #"Raggruppate righe" = Table.Group(Origine, {"NAME"}, {{"recID", each _[RECORD ID]}}),
    #"Valori estratti" = Table.TransformColumns(#"Raggruppate righe", {"recID", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    sdc = Table.SplitColumn(#"Valori estratti", "recID", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv))
in
    sdc

View solution in original post

AlB
Community Champion
Community Champion

Hi @katemke 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKzFUIzs0syVCK1YlWMgKJJOalKnjlZ+QV5+eBBY2Bgn6ZydkKAaklqUXFYDEToJh3YklGpYJXYm4qRMwUwzgzkEh+qoJLfiqYb45uUiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"RECORD ID" = _t, NAME = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RECORD ID", Int64.Type}, {"NAME", type text}}),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"NAME"}, {{"Count", each Text.Combine(List.Transform([RECORD ID], each Text.From(_)), "|") }}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Count", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Count.1", "Count.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Count.1", Int64.Type}, {"Count.2", Int64.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Count.1", "Record ID 1"}, {"Count.2", "Record ID 2"}})
in
    #"Renamed Columns"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @katemke 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKzFUIzs0syVCK1YlWMgKJJOalKnjlZ+QV5+eBBY2Bgn6ZydkKAaklqUXFYDEToJh3YklGpYJXYm4qRMwUwzgzkEh+qoJLfiqYb45uUiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"RECORD ID" = _t, NAME = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RECORD ID", Int64.Type}, {"NAME", type text}}),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"NAME"}, {{"Count", each Text.Combine(List.Transform([RECORD ID], each Text.From(_)), "|") }}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Count", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Count.1", "Count.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Count.1", Int64.Type}, {"Count.2", Int64.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Count.1", "Record ID 1"}, {"Count.2", "Record ID 2"}})
in
    #"Renamed Columns"

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Anonymous
Not applicable

this code should work also in case you have more than two recIDs by name

 

 

 

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKzFUIzs0syVCK1YlWMgKJJOalKnjlZ+QV5+eBBY2Bgn6ZydkKAaklqUXFYDEToJh3YklGpYJXYm4qRMwUwzgzkEh+qoJLfiqYb45uUiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"RECORD ID" = _t, NAME = _t]),
    #"Modificato tipo" = Table.TransformColumnTypes(Origine,{{"RECORD ID", Int64.Type}, {"NAME", type text}}),
    #"Raggruppate righe" = Table.Group(#"Modificato tipo", {"NAME"}, {{"recID", each _[RECORD ID]}}),
    #"Valori estratti" = Table.TransformColumns(#"Raggruppate righe", {"recID", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    scd = Table.SplitColumn(#"Valori estratti", "recID", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv))
in
    scd

 

 

 

let
    Origine = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKzFUIzs0syVCK1YlWMgKJJOalKnjlZ+QV5+eBBY2Bgn6ZydkKAaklqUXFYDEToJh3YklGpYJXYm4qRMwUwzgzkEh+qoJLfiqYb47FJAs0NZYYphgbYwgZGqCbFAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"RECORD ID" = _t, NAME = _t]),
    #"Raggruppate righe" = Table.Group(Origine, {"NAME"}, {{"recID", each _[RECORD ID]}}),
    #"Valori estratti" = Table.TransformColumns(#"Raggruppate righe", {"recID", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    sdc = Table.SplitColumn(#"Valori estratti", "recID", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv))
in
    sdc

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.