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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
As9124141636
Helper I
Helper I

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"

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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