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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
botaac
Frequent Visitor

Combine multiple rows into one row

I have the following table 

NameID1Item TypeID2ID3USD AmountID4RankContractsNotes
Bank1  8910      
Bank1    100SH782400  
Bank1123Vendor       
Bank1   456     

 

Utilizing DAX or Power Query, I need it to be transformed to the following

NameID1Item TypeID2ID3USD AmountID4RankContractsNotes
Bank1123Vendor8910456100SH782400  

 

I utilized the SUMMARIZE function and pulled all of those datafields into it, but still get the rows being separated.

1 REPLY 1
Syk
Super User
Super User

In Power Query I pasted your data into a table and achieved that result with this M code.
The first thing it does is transposes the table so your headers are now rows in column1. Then I replaced all the " " values with nulls and created a custom column to get the first non-null value (the ?? in the code below means to coalesce) This gets the first value from each of those columns and returns it as 1 column which I named Value.
Then I removed columns 2-5 and pivoted the header column (column1) with 'Value' as the values using the "Don't aggregate" under advanced options of the pivot column dialog box.

Hope this helps!

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kvMTVXSUfJ0MQSRJam5CiGVBRARIzBpDCRDg10UHHPzS/NKwEImQDIoMS8bSDnn55UUJSaXFAPZfvklqcVKsTrRSk5ASZB5ClBsYWlogMRFxdg0wLChAUhfsIe5BcgxJgYGWHUZGoEcGZaal5JfhNMafFaZmJphVx8LAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t, #"(blank).5" = _t, #"(blank).6" = _t, #"(blank).7" = _t, #"(blank).8" = _t, #"(blank).9" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}, {"(blank).5", type text}, {"(blank).6", type text}, {"(blank).7", type text}, {"(blank).8", type text}, {"(blank).9", type text}}),
    #"Transposed Table" = Table.Transpose(#"Changed Type"),
    #"Replaced Value" = Table.ReplaceValue(#"Transposed Table"," ",null,Replacer.ReplaceValue,{"Column2", "Column3", "Column4", "Column5"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value", "Value", each [Column2] ?? [Column2] ?? [Column3] ?? [Column4] ??[Column5]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Column2", "Column3", "Column4", "Column5"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Column1]), "Column1", "Value")
in
    #"Pivoted Column"

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.