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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Ramon_CN
Regular Visitor

Table column to rows

Hello wise Friends,

I have the following input table:

Ref ConjuntCodi iniCodi Fi
Cj1iniFi
Cj2iniFi

And would like to transform it in Power Query with the following output

Ref ConjuntCodi
Cj1Ini
Cj1Fi
Cj2ini
Cj2Fi

 

The aim is to append this table to a previous one and add delimiter rows at the start and end of a collection of groups by  Ref. Conjunt Column.  

Although it might be very simple, I've tried my best by unpivoting in different ways, but with no success.

Any help would be appreciated. 

Thanks, folks.  

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs4yVNJRyszLBJJumUqxOiAhIxShWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Ref Conjunt" = _t, #"Codi ini" = _t, #"Codi Fi" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref Conjunt", type text}, {"Codi ini", type text}, {"Codi Fi", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Ref Conjunt"}, "Attribute", "Codi"),
    #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Ref Conjunt", "Codi"})
in
    #"Removed Other Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs4yVNJRyszLBJJumUqxOiAhIxShWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Ref Conjunt" = _t, #"Codi ini" = _t, #"Codi Fi" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref Conjunt", type text}, {"Codi ini", type text}, {"Codi Fi", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Ref Conjunt"}, "Attribute", "Codi"),
    #"Removed Other Columns" = Table.SelectColumns(#"Unpivoted Other Columns",{"Ref Conjunt", "Codi"})
in
    #"Removed Other Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Thanks a lot @lbendlin 

It worked exactly as I wanted.

A blank Query as a starting point with your code. Then Change the data origin

And Great! 🙂

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.