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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Facing challenges in pivoting the data

Hi Team,

Please help me to transform the below data in required format

I have some data in the below format.

AttributeValue
Emp nameJohn
DeptMathematics
Emp ID123
Emp nameDaniel
DeptScience
Emp ID124
Emp nameMohammed
DeptHistory
Emp ID125
Emp nameAndreas
DeptEnglish
Emp ID126
Emp nameRichard
DeptGeography
Emp ID127

 

Now i need to transform this as below.

Emp IDEmp nameDept
JohnMathematics123
DanielScience124
MohammedHistory125
AndreasEnglish126
RichardGeography127

 

Regards,

Priyanga

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
that is basically an unstacking exercise where you need an ID column for each row. You can create that as follows:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc0/C8IwEAXwryI3d/H/LLRohS46hgxHejQHzSUkWfz2VhGJcbx378dTCjoXVoKOoIGrtwK6UdBSyMs9YLbkMLNJ7/hV7dvlsd5sv8HHtihMc6nvhkkM1XJXy8FbdI7G0l44ZR8ftd3X9iRjJEwl7WSaOdmaHmp6Y2Mx/qyeyU8Rg/3bPYLWTw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Attribute = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Attribute", type text}, {"Value", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, 3), Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Integer-Divided Column", List.Distinct(#"Integer-Divided Column"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

See steps: "Add Index" and "Integer-Divide Column".

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

=Table.Combine(List.Transform(Table.Split(PreviousStepName,3),each Table.PromoteHeaders(Table.Transpose(_))))

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
that is basically an unstacking exercise where you need an ID column for each row. You can create that as follows:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc0/C8IwEAXwryI3d/H/LLRohS46hgxHejQHzSUkWfz2VhGJcbx378dTCjoXVoKOoIGrtwK6UdBSyMs9YLbkMLNJ7/hV7dvlsd5sv8HHtihMc6nvhkkM1XJXy8FbdI7G0l44ZR8ftd3X9iRjJEwl7WSaOdmaHmp6Y2Mx/qyeyU8Rg/3bPYLWTw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Attribute = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Attribute", type text}, {"Value", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, 3), Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Integer-Divided Column", List.Distinct(#"Integer-Divided Column"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

See steps: "Add Index" and "Integer-Divide Column".

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Thanks a lot!!!  @ImkeF , @wdx223_Daniel 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors