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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

change row values to column names

Hi , I want to change row values to column names. In the Power BI query there is Pivot column option, but since I have two columns as value, that solution did not work for me.

Thanks in advance!

Post_Forum.PNG

2 REPLIES 2
PijushRoy
Super User
Super User

Hi @Anonymous 

Please create a Blank query in PQ and paste the code in Advance Editor

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtI1MAQiJR0lRyAGChgaGoG5LqkFiUUlual5JUCOU2Y+lIzVwa/NOR+mJTEJCIGMvNKcHMLaMksyq1LzYvKAbLcgRygZGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date#(lf)" = _t, Database = _t, Identity = _t, Names = _t, Source1 = _t, Source2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date#(lf)", type date}, {"Database", type text}, {"Identity", Int64.Type}, {"Names", type text}, {"Source1", type text}, {"Source2", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date#(lf)", "Database", "Identity", "Names"}, "Attribute", "Value"),
    #"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Names]), "Names", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute", "Source"}})
in
    #"Renamed Columns"

 

Image

PijushRoy_0-1701878403886.png


If solved your requirement, please mark this answer as SOLUTION.
If this comment helps you, appreciate your KUDOS

Thanks
Pijush




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





rsbin
Super User
Super User

@Anonymous ,

You need to use a combination of Unpivot Columns and Pivot Columns.

Please see attached pbix file for detailed Power Query Transformation steps.  Trust you can follow along.

In the future, please paste sample data as text, not as a picture.  This will make it easier for folks to assist.

Regards,

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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