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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
bharukc
Helper I
Helper I

Pivot multiple values of one id

I have a table that I need to pivot. Pivoting should create multiple rows per id

parent.   Child.   Level

C              A.         1

C             B.          2

A.             D.          1

C.             E.           1

end result

parent.  Level 1.     Level 2

C.            A.             B

C.            E.              Null

A.            D

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @bharukc ,

I created a sample pbix file(see the attachment), please check if that is what you want.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclbSUXLUAxKGSrE6EK4TiGsE5oJlXJCkQUxXKD8WAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"parent." = _t, #"Child." = _t, Level = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"parent.", type text}, {"Child.", type text}, {"Level", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"Level", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"Level", type text}}, "en-US")[Level]), "Level", "Child."),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"1", "Level 1"},{"2", "Level 2"}})
in
    #"Renamed Columns"

yingyinr_0-1666751974649.png

Best Regards

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

View solution in original post

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @bharukc ,

I created a sample pbix file(see the attachment), please check if that is what you want.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclbSUXLUAxKGSrE6EK4TiGsE5oJlXJCkQUxXKD8WAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"parent." = _t, #"Child." = _t, Level = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"parent.", type text}, {"Child.", type text}, {"Level", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"Level", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"Level", type text}}, "en-US")[Level]), "Level", "Child."),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"1", "Level 1"},{"2", "Level 2"}})
in
    #"Renamed Columns"

yingyinr_0-1666751974649.png

Best Regards

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

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors