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
howeixiong
Regular Visitor

Transpose every 5 rows into Column

Hi there,

I am writing in to seek guidance.

I would like to perform the following.

Before:

Screenshot 2024-09-19 at 11.01.10 AM.png

Result:

Screenshot 2024-09-19 at 11.00.42 AM.png

Thank you

4 ACCEPTED SOLUTIONS
m_dekorte
Resident Rockstar
Resident Rockstar

Hi @howeixiong,

Give this a go:

let
    Source = YourTable,
    GroupedRows = Table.Group(Source, {"FieldDescription"}, {{"temp", each _[Value] }}),
    NewTable = Table.FromColumns( GroupedRows[temp], GroupedRows[FieldDescription] )
in
    NewTable

I hope this is helpful

View solution in original post

slorin
Super User
Super User

Hi @howeixiong 

Another solution

 

let
Source = Your_Source,
IntergerDivide = Table.TransformColumns(Source, {{"Index", each Number.IntegerDivide(_, 5), Int64.Type}}),
Pivot = Table.Pivot(IntergerDivide, List.Distinct(IntergerDivide[FieldDescription]), "FieldDescription", "Value"),
Remove_Index = Table.RemoveColumns(Pivot,{"Index"})
in
Remove_Index

Stéphane 

View solution in original post

Omid_Motamedise
Super User
Super User

You can solve this problem in different way one is splitting the table every 5 rows as the below code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc+3DcAwDETRVQzWKpRDKYcN3BHafw3TZxCgCxX3ig+KmTw5mvLOec8t0HJMQeauFEFR5qGUQOmdShmUZV5KBVRsvoKqzTdQs/kO6jY/QMPmg/9u/d8vH1gP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [index = _t, #"field description" = _t, value = _t]),
    #"Removed Columns" = Table.Combine(List.Transform(Table.Split(Table.RemoveColumns(Source,{"index"}),5),each Table.PromoteHeaders(Table.Transpose(_))))
in
    #"Removed Columns"

If my answer helped solve your issue, please consider marking it as the accepted solution.

View solution in original post

dufoq3
Super User
Super User

Hi @howeixiong, another solution:

similar to @AlienSx, but handles null values if needed

 

Output

dufoq3_0-1726748787901.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc+3DcAwDETRVQzWKpRDKYcN3BHafw3TZxCgCxX3ig+KmTw5mvLOec8t0HJMQeauFEFR5qGUQOmdShmUZV5KBVRsvoKqzTdQs/kO6jY/QMPmg/9u/d8vH1gP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, FieldDescription = _t, Value = _t]),
    Transformed = [ a = List.Buffer(Source[Value]),
    b = List.Split({0..Table.RowCount(Source)-1}, 5),
    c = List.TransformMany(b, each {List.Transform(_, (x)=> a{x})}, (x,y)=> if List.Count(y) = 5 then y else y & List.Repeat({null}, 5 - List.Count(y)) ),
    d = #table(List.FirstN(Source[FieldDescription], 5), c )
  ][d]
in
    Transformed

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Can't you just remove the index, then use the Pivot GUI, using FieldDescription as the pivot column and Values as the values, choosing "Do Not Aggregate"? Seems like the solutions above depend on there being exactly 5 unique values in FieldDescription.

 

--Nate

dufoq3
Super User
Super User

Hi @howeixiong, another solution:

similar to @AlienSx, but handles null values if needed

 

Output

dufoq3_0-1726748787901.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc+3DcAwDETRVQzWKpRDKYcN3BHafw3TZxCgCxX3ig+KmTw5mvLOec8t0HJMQeauFEFR5qGUQOmdShmUZV5KBVRsvoKqzTdQs/kO6jY/QMPmg/9u/d8vH1gP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, FieldDescription = _t, Value = _t]),
    Transformed = [ a = List.Buffer(Source[Value]),
    b = List.Split({0..Table.RowCount(Source)-1}, 5),
    c = List.TransformMany(b, each {List.Transform(_, (x)=> a{x})}, (x,y)=> if List.Count(y) = 5 then y else y & List.Repeat({null}, 5 - List.Count(y)) ),
    d = #table(List.FirstN(Source[FieldDescription], 5), c )
  ][d]
in
    Transformed

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

AlienSx
Super User
Super User

#table(List.FirstN(Source[FieldDescription], 5), List.Split(Source[Value], 5))
Omid_Motamedise
Super User
Super User

You can solve this problem in different way one is splitting the table every 5 rows as the below code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc+3DcAwDETRVQzWKpRDKYcN3BHafw3TZxCgCxX3ig+KmTw5mvLOec8t0HJMQeauFEFR5qGUQOmdShmUZV5KBVRsvoKqzTdQs/kO6jY/QMPmg/9u/d8vH1gP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [index = _t, #"field description" = _t, value = _t]),
    #"Removed Columns" = Table.Combine(List.Transform(Table.Split(Table.RemoveColumns(Source,{"index"}),5),each Table.PromoteHeaders(Table.Transpose(_))))
in
    #"Removed Columns"

If my answer helped solve your issue, please consider marking it as the accepted solution.
slorin
Super User
Super User

Hi @howeixiong 

Another solution

 

let
Source = Your_Source,
IntergerDivide = Table.TransformColumns(Source, {{"Index", each Number.IntegerDivide(_, 5), Int64.Type}}),
Pivot = Table.Pivot(IntergerDivide, List.Distinct(IntergerDivide[FieldDescription]), "FieldDescription", "Value"),
Remove_Index = Table.RemoveColumns(Pivot,{"Index"})
in
Remove_Index

Stéphane 

m_dekorte
Resident Rockstar
Resident Rockstar

Hi @howeixiong,

Give this a go:

let
    Source = YourTable,
    GroupedRows = Table.Group(Source, {"FieldDescription"}, {{"temp", each _[Value] }}),
    NewTable = Table.FromColumns( GroupedRows[temp], GroupedRows[FieldDescription] )
in
    NewTable

I hope this is helpful

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.