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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
lazer1
New Member

Way to transform data from a pivoted like format into a more structured format

Hello,

 

I am trying to figure out a way to use power query to transform a table of data into another. See pic below. I am trying to turn the table on the left into the table on the right. I was having trouble finding the right way to describe this, and was having a hard time finding if there were any already posted similar solutions. Any help is appreciated. Thanks!

 

2023-06-19 14_26_57-new way to query data - Excel.png

 

TypeTray 1Tray 2Tray 3Total
Defect 1361726
Defect 235715
Defect 31331531
Defect 416161345
Defect 5221519
Defect 657315
Defect 7183425
1 ACCEPTED SOLUTION
baghdadi62
Resolver III
Resolver III

1- Remove "Total" Column.

2- Right mouse click on Type column and select "Unpivot Other Columns".
3- Replace "Tray" With Empty String on "Attribute" Column.

Unpivot StepUnpivot Step

 

All steps:

All stepsAll steps

View solution in original post

4 REPLIES 4
baghdadi62
Resolver III
Resolver III

1- Remove "Total" Column.

2- Right mouse click on Type column and select "Unpivot Other Columns".
3- Replace "Tray" With Empty String on "Attribute" Column.

Unpivot StepUnpivot Step

 

All steps:

All stepsAll steps

Thank you!!!

I'm glad I could help.

Papermain
Frequent Visitor

let
    Source = Excel.CurrentWorkbook(){[Name="DefectTable"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Tray 1", Int64.Type}, {"Tray 2", Int64.Type}, {"Tray 3", Int64.Type}, {"Total", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Type"}, "Attribute", "Value"),
    #"Renamed Columns1" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Value", "Defect count"}}),
    #"Renamed Columns" = Table.RenameColumns(#"Renamed Columns1",{{"Attribute", "Tray"}}),
    #"Lowercased Text" = Table.TransformColumns(#"Renamed Columns",{{"Tray", Text.Lower, type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Lowercased Text","tray","",Replacer.ReplaceText,{"Tray"}),
    #"Filtered Rows" = Table.SelectRows(#"Replaced Value", each ([Tray] <> "total")),
    #"Trimmed Text" = Table.TransformColumns(#"Filtered Rows",{{"Tray", Text.Trim, type text}})
in
    #"Trimmed Text"

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors