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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
F5447895
New Member

Convert multiple rows into one row with sorted columns

Hello,

 

please see the picture:

1.jpg

I have as input data a table where the "Number" may occurs in several lines or just in one.

As output data i need a table where the "Number" is only in 1 line, but i still need all informations of the input data.

So i would like to convert theese "Value 2" informations into columns.

If that helps it could be fixed to 3 Columns, more "Value 2"-Types doesnt appear per "Number".

 

Do you have an idea how i could do it?

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.  You need to select your first two columns then choose Group By and accept the default Count option.  You then need to modify the code in the Formula Bar to match the below, and then split the column by the "_" to get your result.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaoE4kQgNlaK1UGIJAGxEVjECMiqAOJkIDYEixhDeSlAbIIikgrEFigiaUBsBhYxAbLKgDgdbpcp1J4MiF2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, #"Value 1" = _t, #"Value 2" = _t, Amount = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Number", "Value 1"}, {{"Value 2", each Text.Combine([Value 2], "_")}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Value 2", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Values.1", "Values.2", "Values.3"})
in
    #"Split Column by Delimiter"

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.  You need to select your first two columns then choose Group By and accept the default Count option.  You then need to modify the code in the Formula Bar to match the below, and then split the column by the "_" to get your result.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaoE4kQgNlaK1UGIJAGxEVjECMiqAOJkIDYEixhDeSlAbIIikgrEFigiaUBsBhYxAbLKgDgdbpcp1J4MiF2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t, #"Value 1" = _t, #"Value 2" = _t, Amount = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Number", "Value 1"}, {{"Value 2", each Text.Combine([Value 2], "_")}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "Value 2", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Values.1", "Values.2", "Values.3"})
in
    #"Split Column by Delimiter"

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Perfect, thank you. 👍

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.