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
ChaChaBones
New Member

I have a 6 column table and need to transpose two columns and eliminate duplicate rows.

My first post.  Hope I do it right!

I have the data below in the "Current Data" table and I need it to be arranged like the data in the "Desired Data" table below it.  The original is coming from sql and I'm using the final data in Excel.  I can do it in Excel with a pivot table but there is vastly more data than I'm representing here and I'd rather get it done in Power Query so I can update the data without manipulate it every month.  Thanks in advance.

 

Current Data:

DateCustomer#SO#Inv#RptGrpAmount
06/25/24Customer 01OLSSO001OLSINV004001_Rev6,491.00
06/25/24Customer 01OLSSO001OLSINV004003_Cost313.48
06/25/24Customer 01OLSSO001OLSINV004004_DSRev1,500.00
06/25/24Customer 01OLSSO001OLSINV004005_DSCost1,050.00
06/04/24Customer 02SO06218STDINV06043001_Rev386.20
06/04/24Customer 02SO06218STDINV06043003_Cost113.88
06/04/24Customer 02SO06218STDINV06043004_DSRev950.00
06/04/24Customer 02SO06218STDINV06043005_DSCost700.00

 

Desired table:

DateCustomer#SO#Inv#001_Rev003_Cost004_DSRev005_DSCost
06/25/24Customer 01OLSSO001OLSINV0046,491.00313.4815001050
06/04/24Customer 02SO06218STDINV06043386.20113.88950700
2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZDLCsIwEEV/RbIO6Z28TNftRhALVtyUklWXUrDV73eCVavLuLszDIc7p+sEfKFdoa2QorpN83gZrhsQT82+bRu84u5wBtIRb+JxuHPy0pakANHLHIyJ1TjNHA0ZZUMmxca6fdYh6YD8Oo5BSyGScGsS7C9J88QYrymkdKoTyMOaL0EmeKWzKW8/xH5CyMV8BJV/PbXys1089w8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Customer#" = _t, #"SO#" = _t, #"Inv#" = _t, RptGrp = _t, Amount = _t]),
    #"Pivoted Column" = Table.Pivot(Source, List.Distinct(Source[RptGrp]), "RptGrp", "Amount")
in
    #"Pivoted Column"

View solution in original post

Hi @ChaChaBones, graphical solution by @lbendlin:

 

dufoq3_0-1723045067038.png

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

4 REPLIES 4
ChaChaBones
New Member

Thank you both for your solutions as they were both helpful.  However, at this point, I believe the first solution from @lbendlin  comes closer to fully solving my problem.  The lack of a complete solution at this point is my fault because my original test data was not complete on two fronts.

 

First, I simplified the original test data and now realize I over-simplified it so it was not complete. 

 

Second, my data source is actually from a SQL View and I don't know how to adjust the syntax in the first solution to accomodate for that.

 

I tried to tweak the first solution to accomodate for my two misfires but I couldn't get it to work.   I will provided beter data shortly.

Just for your information: both solutions are exactly the same 😉


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZDLCsIwEEV/RbIO6Z28TNftRhALVtyUklWXUrDV73eCVavLuLszDIc7p+sEfKFdoa2QorpN83gZrhsQT82+bRu84u5wBtIRb+JxuHPy0pakANHLHIyJ1TjNHA0ZZUMmxca6fdYh6YD8Oo5BSyGScGsS7C9J88QYrymkdKoTyMOaL0EmeKWzKW8/xH5CyMV8BJV/PbXys1089w8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Customer#" = _t, #"SO#" = _t, #"Inv#" = _t, RptGrp = _t, Amount = _t]),
    #"Pivoted Column" = Table.Pivot(Source, List.Distinct(Source[RptGrp]), "RptGrp", "Amount")
in
    #"Pivoted Column"

Hi @ChaChaBones, graphical solution by @lbendlin:

 

dufoq3_0-1723045067038.png

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors