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
LukeReds
Helper II
Helper II

Transform a table with n rows in a single cell for every guy

Hi to everyone, i have this table, an empty cell divide one guy from the other (of course there are several guys in the table, not only 2)

 

tab.jpg

 

I need to have this data using only power query (no dax, no vba). The numbers of rows for every guy can change

 

tab.jpg

 

Thank you in advance

 

 

1 ACCEPTED SOLUTION
Omid_Motamedise
Super User
Super User

Use this code

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"Count", each Text.Combine([Column1],"#(lf)"), type nullable text}},0,(a,b)=>Number.From(b[Column1]=null))
in
    #"Grouped Rows"

 

 

result in 

 

Omid_Motamedise_0-1727213611348.png

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

4 REPLIES 4
LukeReds
Helper II
Helper II

tahnk you to everyone, i got the solution!

Anonymous
Not applicable

Hi,

Thanks for the solutions Omid_Motamedise  and jgeddes offered, and i want to offer some more information for user to refer to.

hello @LukeReds ,you can create a blank query and input the following code to advanced editor.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1QGShhDKCEIZgykw4QQhIfJOEHkniLyTCYQyhVBmCE3OEBKiyRmiyRmoKRYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each let a=[Index]
in Table.RowCount(Table.SelectRows(#"Added Index",each [Index]<a and [Column1]=""))),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"Count", each Text.Combine([Column1],"
")}}),
    #"Trimmed Text" = Table.TransformColumns(#"Grouped Rows",{{"Count", Text.Trim, type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Trimmed Text",{"Custom"})
in
    #"Removed Columns"

Original data

vxinruzhumsft_0-1727232098882.png

After transforming.

vxinruzhumsft_1-1727232117504.png

Best Regards!

Yolo Zhu

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

 

 

 

Omid_Motamedise
Super User
Super User

Use this code

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column1"}, {{"Count", each Text.Combine([Column1],"#(lf)"), type nullable text}},0,(a,b)=>Number.From(b[Column1]=null))
in
    #"Grouped Rows"

 

 

result in 

 

Omid_Motamedise_0-1727213611348.png

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
jgeddes
Super User
Super User

I am not sure what format you require for final data but here is an example of turning...

jgeddes_0-1727203753749.png

into this...

jgeddes_1-1727203774559.png

Example code...

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TYy9CoAwDIRfpXR2aKs+gauCQ7fSIUiHQDTQ1sWnF1L8WZI77r4LQS+QkXXsgl4RrgtEOmONUQsSHC3bEpGyrh/EyZlPLK09cS6tZoXznPHPPVhNpMahF512QPrGPO7yiTeoyIcYyAnelT8Vbw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    addInitialIndex = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    groupBlankCount = Table.Group(addInitialIndex, {"Column1"}, {{"_nested", each _, type table [Column1=nullable text, Index=number]}}),
    addBlankInstance = Table.TransformColumns(groupBlankCount, {{"_nested", each Table.AddIndexColumn(_, "instance", 1, 1, Int64.Type)}}),
    expandNestedRows = Table.ExpandTableColumn(addBlankInstance, "_nested", {"Index", "instance"}, {"Index", "instance"}),
    sortToOriginalOrder = Table.Buffer(Table.Sort(expandNestedRows, {"Index", Order.Ascending})),
    addOccurenceColumn = Table.AddColumn(sortToOriginalOrder, "Occurence", each if [Column1] = "" then [instance] else null),
    fillUp = Table.FillUp(addOccurenceColumn,{"Occurence"}),
    addLastOccurence = Table.ReplaceValue(fillUp,null,List.Max(fillUp[Occurence])+1,Replacer.ReplaceValue,{"Occurence"}),
    removeColumns = Table.RemoveColumns(addLastOccurence,{"Index", "instance"}),
    removeBlankRows = Table.SelectRows(removeColumns, each ([Column1] <> "")),
    groupByOccurence = Table.Group(removeBlankRows, {"Occurence"}, {{"_nestedRows", each Table.SelectColumns(_, {"Column1"}), type table [Column1=nullable text, Custom=number]},{"nestedRowCount", each Table.RowCount(_), Int64.Type}}),
    transposeNestedTables = Table.TransformColumns(groupByOccurence, {{"_nestedRows", each Table.Transpose(_)}}),
    columnList = List.Generate(()=>1, each _ <= List.Max(transposeNestedTables[nestedRowCount]), each _ + 1, each "Column"&Text.From(_)),
    selectNeededColumn = Table.SelectColumns(transposeNestedTables, {"_nestedRows"}),
    expandNested = Table.ExpandTableColumn(selectNeededColumn, "_nestedRows", columnList)
in
    expandNested

Hopefully this gets you pointed in the right direction.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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