cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
As9124141636
Frequent Visitor

unpivot automatically

I have an Excel file contains

 

 

 

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @As9124141636 ,

 

I think I found a solution.

I split the table into different years. Then I'm looping over each table and do the transformation.

 

Please check the attached file. When you open the Power BI file, you have to adapt the parameter "PathToXLSXFile" to the path and name of your XLSX file, for example to "C:\temp\Transpose.xlsx".

Afterwards the rest should load automatically.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic

View solution in original post

4 REPLIES 4
selimovd
Super User
Super User

Hey @As9124141636 ,

 

I think I found a solution.

I split the table into different years. Then I'm looping over each table and do the transformation.

 

Please check the attached file. When you open the Power BI file, you have to adapt the parameter "PathToXLSXFile" to the path and name of your XLSX file, for example to "C:\temp\Transpose.xlsx".

Afterwards the rest should load automatically.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic

Ashish_Mathur
Super User
Super User

Hi,

Why is your data in such a poor format?  Why not clean it up to atlest have all years listed down a single column and then upload the Data to PowerBI?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@As9124141636 , Having them in one sheet is not a good idea. Check if this code can help

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZJLEgMhCETvMuss5NMCZ5nK/a8RGFNJqsK4QpQHbet5HnQ8DjIxWC7YY4yMgolKGdPrnIfQzIVD8Y3Px3lwlVEw39M+ERVZ3vkHlswMCNqMNh0eP/TMdnrRWscQ0blTTkLSDq8yUtiq7/HsbtHSNTNb80Xd0KKpvqXtkj5VNnQ+Crz3zS/faMRGucfsldeuiUI2o8EAtTSNdXHzjevp6fpO/3h1hdK62M1/CTLu6dp24uXqjXZVt+bFny8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"2011" = _t, A = _t, B = _t, C = _t, D = _t, E = _t, F = _t, G = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"2011", Int64.Type}, {"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}, {"D", Int64.Type}, {"E", Int64.Type}, {"F", Int64.Type}, {"G", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"A", "B", "C", "D", "E", "F", "G"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Year"}, {"Value", "Month"}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Year", "Month"}, "Attribute", "Value")
in
    #"Unpivoted Other Columns"


Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || 50+Power Query List Functions : Learn Power Query List
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

thanks

i think you did it for one year. i want to do for all years and if new year added in excel, transform it automatically.

I think the solution is create list of years and transform every year (in a loop) then finally append. but i dont know how to do in power query.

Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Dev Camp Session 26

Check it Out!

Mark your calendars and join us on Thursday, September 29 at 11a PDT for a great session with Ted Pattison!

Top Solution Authors