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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Mu
Frequent Visitor

Attempting to Pivot Colum

Hello,

I am downloading data from an XML file and it is being imported like this

Mu_0-1690405747305.png

I would like to transform the data to look like this

Mu_1-1690405764983.png

I tried pivoting the column without aggregating but I don't think it spits out an error. As far as I understand, simply pivoting won't work because each row is not supposed to have its own column. Thanks.

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

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. The key is to add an index column (starting from 1), divide it by 4, then round it up. You can then pivot on your original column, using your other original column as values (also choose "Don't Aggregate" in the options).

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg12VNJRcs4vzSspqlSK1YlWAvE9S1JzwRwjAyNjID8yNbEIzDc0APLCEnNKU8HcUG80zU5omo2QNZsi9MYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each _ / 4, type number}}),
    #"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Rounded Up", List.Distinct(#"Rounded Up"[Column2]), "Column2", "Column1")
in
    #"Pivoted Column"

 

Pat

Microsoft Employee

View solution in original post

1 REPLY 1
ppm1
Solution Sage
Solution Sage

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. The key is to add an index column (starting from 1), divide it by 4, then round it up. You can then pivot on your original column, using your other original column as values (also choose "Don't Aggregate" in the options).

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg12VNJRcs4vzSspqlSK1YlWAvE9S1JzwRwjAyNjID8yNbEIzDc0APLCEnNKU8HcUG80zU5omo2QNZsi9MYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    #"Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each _ / 4, type number}}),
    #"Rounded Up" = Table.TransformColumns(#"Divided Column",{{"Index", Number.RoundUp, Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Rounded Up", List.Distinct(#"Rounded Up"[Column2]), "Column2", "Column1")
in
    #"Pivoted Column"

 

Pat

Microsoft Employee

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors