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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Formatting data from multiple variable rows to one single row

I'm looking at consolidating mutlipe rows into one row, although the number of rows per items is variable. Looking for some advice for either in power query or dax to perform this.

 

Might be easier to explain with an example. Current data looks like this

Supplier No.NameContact TypeContact
222ABCBus000 000 000
222ABVBus123 123 123
222ABCFax000 000 000
222ABCEmail@mail.com
333CDFBus000 000 000 
333CDFEmail@mail.com
444XYZEmail@mail.com

 

Want to transform it into this

Supplier No.NameContact TypeContactContact TypeContactContact TypeContactContact TypeContact
222ABCBus000 000 000Bus123 123 123Fax000 000 000Email@mail.com
333CDFBus000 000 000     Email@mail.com
444XYZ      Email@mail.com

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution. You can copy-paste the code in a blank query to see the details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIyUtJRcnRyBpJOpcVA0sDAQAGKlWJ1ECrC4CoMjYwVoBhFBcgMt8QKPGaAVLjmJmbmAGkHEK2XnJ8LVmFsbAwUc3Zxw+YOBQwl2A0xMTEBikVERmFXEQsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Supplier No." = _t, Name = _t, #"Contact Type" = _t, Contact = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Supplier No.", Int64.Type}, {"Name", type text}, {"Contact Type", type text}, {"Contact", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Supplier No."}, "Attribute", "Value"),
    #"Pivoted Column" = Table.Pivot(#"Unpivoted Other Columns", List.Distinct(#"Unpivoted Other Columns"[Attribute]), "Attribute", "Value",each Text.Combine(List.Sort(_), ",")),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Pivoted Column", "Name", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Name.1", "Name.2"}),
    #"Replaced Value"=Table.ReplaceValue(#"Split Column by Delimiter",each[Contact Type],each if [Contact Type]="Bus,Email" then "Bus,,Email" else if [Contact Type]="Email" then ",,Email" else [Contact Type], Replacer.ReplaceValue,{"Contact Type"} ),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Replaced Value", "Contact Type", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Contact Type.1", "Contact Type.2", "Contact Type.3","Contact Type.4"}),
    #"Replaced Value2"=Table.ReplaceValue(#"Split Column by Delimiter1",each[Contact],each if [Contact]="000 000 000 ,@mail.com" then "000 000 000 ,,,@mail.com" else if [Contact]="@mail.com" then ",,,@mail.com" else [Contact], Replacer.ReplaceValue,{"Contact"} ),
    #"Split Column by Delimiter2" = Table.SplitColumn(#"Replaced Value2", "Contact", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Contact.1", "Contact.2", "Contact.3", "Contact.4"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter2",{"Name.2"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Supplier No.", "Name.1", "Contact Type.1", "Contact.1", "Contact Type.2", "Contact.2", "Contact Type.4", "Contact.3", "Contact Type.3", "Contact.4"})
in
    #"Reordered Columns"

Get the correct result:

vyanjiangmsft_0-1685613309176.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution. You can copy-paste the code in a blank query to see the details.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIyUtJRcnRyBpJOpcVA0sDAQAGKlWJ1ECrC4CoMjYwVoBhFBcgMt8QKPGaAVLjmJmbmAGkHEK2XnJ8LVmFsbAwUc3Zxw+YOBQwl2A0xMTEBikVERmFXEQsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Supplier No." = _t, Name = _t, #"Contact Type" = _t, Contact = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Supplier No.", Int64.Type}, {"Name", type text}, {"Contact Type", type text}, {"Contact", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Supplier No."}, "Attribute", "Value"),
    #"Pivoted Column" = Table.Pivot(#"Unpivoted Other Columns", List.Distinct(#"Unpivoted Other Columns"[Attribute]), "Attribute", "Value",each Text.Combine(List.Sort(_), ",")),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Pivoted Column", "Name", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Name.1", "Name.2"}),
    #"Replaced Value"=Table.ReplaceValue(#"Split Column by Delimiter",each[Contact Type],each if [Contact Type]="Bus,Email" then "Bus,,Email" else if [Contact Type]="Email" then ",,Email" else [Contact Type], Replacer.ReplaceValue,{"Contact Type"} ),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Replaced Value", "Contact Type", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Contact Type.1", "Contact Type.2", "Contact Type.3","Contact Type.4"}),
    #"Replaced Value2"=Table.ReplaceValue(#"Split Column by Delimiter1",each[Contact],each if [Contact]="000 000 000 ,@mail.com" then "000 000 000 ,,,@mail.com" else if [Contact]="@mail.com" then ",,,@mail.com" else [Contact], Replacer.ReplaceValue,{"Contact"} ),
    #"Split Column by Delimiter2" = Table.SplitColumn(#"Replaced Value2", "Contact", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Contact.1", "Contact.2", "Contact.3", "Contact.4"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter2",{"Name.2"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Supplier No.", "Name.1", "Contact Type.1", "Contact.1", "Contact Type.2", "Contact.2", "Contact Type.4", "Contact.3", "Contact Type.3", "Contact.4"})
in
    #"Reordered Columns"

Get the correct result:

vyanjiangmsft_0-1685613309176.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.