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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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