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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Unpivot Columns

Hi,

 

I am trying to unpivot columns B to M but I am unable to get the desired result in query editor. I can get the desired results in Microsoft Access by writing the query and using Union All. Is it possible to do this in Power Query Editor? I have tried to add an indexed column so that I can sort through the numerical numbers after unpivot coumns B to M, but that didn't help as by unpivoting columns B to M it also changes  the index numbers.

 

Data:

 

PowerBI3861_2-1654737550665.png

 

Desired result:

 

Real OrdersPeriodAmount
532910  Prf Svcs Rev1-60000.00
690296  Lab: External18.22
692025  Overhead: Misc (lab)11.73
5610901  KTI-PTO - Fiber GLASS1-16377.47
605509  Contracts-Other Svcs1833.57
645200  SI Expense Transfers1200.00
690296  Lab: External10.06
692025  Overhead: Misc (lab)13305.90
95142290  TIS-A/N-  salesforce120081.83
532910  Prf Svcs Rev2-60000.00
690296  Lab: External28.22
692025  Overhead: Misc (lab)24.38
5610901  KTI-PTO - Fiber GLASS2-11331.24
605509  Contracts-Other Svcs24962.10
645200  SI Expense Transfers21000.00
690296  Lab: External20.89
692025  Overhead: Misc (lab)23929.57
95142290  TIS-A/N-  salesforce228603.93
532910  Prf Svcs Rev30.00
690296  Lab: External30.00
692025  Overhead: Misc (lab)30.00
5610901  KTI-PTO - Fiber GLASS30.00
605509  Contracts-Other Svcs30.00
645200  SI Expense Transfers30.00
690296  Lab: External30.00
692025  Overhead: Misc (lab)30.00
95142290  TIS-A/N-  salesforce30.00

 

7 REPLIES 7
Anonymous
Not applicable

Here is the link to the data: https://docs.google.com/spreadsheets/d/1EMqc3KrH2J6k5LpQakikSZIH3MgHvpNHu6gZwpYuY40/edit?usp=sharing 

 

I tried the Unpivot Other Columns, but it didn't work out.

Hello,

 

You need more than Unpivoting for your use case. Try the M-Script below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vZJBa8MwDIX/ishpg8az5diJeytjG2XdUprcQg9u6tJCSIcdyn7+5JYx2NnU8FmCKLzk6XVdtnF2gNrvnQ/ZLBMEEpIoCEVooiQqwsQZHq84KTDbzrpMSTSCA6z9AZpLH2DjLvQ015wO4/xfn6JEWW04Gg2wsrs5vHxPzo92iN/JEP9KOjXkqADqi/NHZ/dz+DiFHh4Gu3uMVrDy6hmTVUJRpQU3XAC8t8t83daQw+tp5zy8rRZNE30VWpYlK8prL6QUDIuUf82V4gbg+TxO3vZTyOvpSPpxzdFjKZmK2oXRyETS7RYKOYWqWdJuv9wYHLTejuFwCyr+pkncLVc0oK+lMvfLlZRcMRPfkAbNzexU0kaJAtGQye2yyRdPnzlAsIMLh7Pv3c3kSrAqBhsrzSUzMpX89gc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t, Column11 = _t, Column12 = _t, Column13 = _t]),
    #"Transposed Table" = Table.Transpose(Source),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Transposed Table", {"Column1"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", type text}}),
    RealOrdersName = Table.SelectRows(#"Changed Type", each ([Column1] = "Real Orders")),
    Custom1 = #"Unpivoted Other Columns",
    #"Filtered Rows1" = Table.SelectRows(Custom1, each [Column1] <> "Real Orders"),
    #"Merged Queries" = Table.NestedJoin(#"Filtered Rows1", {"Attribute"}, RealOrdersName, {"Attribute"}, "ColumnName", JoinKind.LeftOuter),
    #"Expanded ColumnName" = Table.ExpandTableColumn(#"Merged Queries", "ColumnName", {"Value"}, {"Real Orders"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded ColumnName",{{"Column1", "Period"}, {"Value", "Amount"}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Renamed Columns",{"Real Orders", "Amount", "Period"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Amount", type number}, {"Period", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Period", Order.Ascending}})
in
    #"Sorted Rows"

Here's a screenshot of the result:

danextian_0-1654745042785.png

 

Sample PBIX - https://drive.google.com/file/d/1TD1fOdwaxP2pVDPp2goKprXVIno9rkch/view?usp=sharing 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Thank you for working on this and sorry for the delayed reply. Would it be possible to have the desired result data in the same sort order (Real Order column) as the original data?

Hi @Anonymous 

I just want to confirm if you resolved this issue? If yes, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.

If you need more help, please let me know.

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi, 

 

I am just waiting to have the desired result data in the same sort order (Real Order column) as the original data. At the moment, I have not been able to resolve the issue. 

danextian
Super User
Super User

Or have you tried Unpivot Other Columns instead by selecting only the column/s that you want to stay pivoted?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
danextian
Super User
Super User

Hi @Anonymous 

 

Please post a sample data that we can copy-paste (not an image) or a link to an Excel file.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors