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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
ngct1112
Post Patron
Post Patron

Power Query - Table transform

Hi,

Here's an interesting situation. Do you think it is possible to tansform the TableA to TableB in powerQuery? Thanks a lot.

Table A 
Product Customer1Customer2Customer3Customer4
A0.1   
A 0.2  
B0.1   
B 0.2  
B  0.3 
B   0.4
C0.1   
C 0.2  

 

Table B 
Product Customer1Customer2Customer3Customer4
A0.10.2  
B0.10.20.30.4
C0.10.2  
3 ACCEPTED SOLUTIONS

Hi @ngct1112 ,

 

Just paste this code on Advanced Editor:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKTylNLlFQ0lFyLi0uyc9NLTJEYhshsY2R2CZKsTrRSo5AEQM9kHoFOIaJK4DljFDEnXCod8KjXgEuZ4xVHCIHcY8zDvOdsZkfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Replaced Value" = Table.ReplaceValue(#"Promoted Headers",".",",",Replacer.ReplaceText,{"Customer1", "Customer2", "Customer3", "Customer4"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Customer1", type number}, {"Customer2", type number}, {"Customer3", type number}, {"Customer4", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Product "}, {{"Customer1", each List.Sum([Customer1]), type number}, {"Customer2", each List.Sum([Customer2]), type number}, {"Customer3", each List.Sum([Customer3]), type number}, {"Customer4", each List.Sum([Customer4]), type number}})
in
#"Grouped Rows"

 

Ricardo



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

Proud to be a Super User!



View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product ", type text}, {"Customer1", type number}, {"Customer2", type number}, {"Customer3", type number}, {"Customer4", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Product "}, "Attribute", "Value"),
    #"Pivoted Column" = Table.Pivot(#"Unpivoted Other Columns", List.Distinct(#"Unpivoted Other Columns"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

Hope this helps.

Untitled.png


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

View solution in original post

This is the Group By version:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKTylNLlFQ0lFyLi0uyc9NLTJEYhshsY2R2CZKsTrRSo5AEQM9kHoFOIaJK4DljFDEnXCod8KjXgEuZ4xVHCIHcY8zDvOdsZkfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Product ", type text}, {"Customer1", type number}, {"Customer2", type number}, {"Customer3", type number}, {"Customer4", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Product "}, {{"Customer1", each List.Max([Customer1]), type number}, {"Customer2", each List.Max([Customer2]), type number}, {"Customer3", each List.Max([Customer3]), type number}, {"Customer4", each List.Max([Customer4]), type number}})
in
    #"Grouped Rows"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product ", type text}, {"Customer1", type number}, {"Customer2", type number}, {"Customer3", type number}, {"Customer4", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Product "}, "Attribute", "Value"),
    #"Pivoted Column" = Table.Pivot(#"Unpivoted Other Columns", List.Distinct(#"Unpivoted Other Columns"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

Hope this helps.

Untitled.png


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

@Ashish_Mathur it work prefectly. Great thanks!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Community Champion
Community Champion

Yes, use Group By



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Could you give a little advice.

When I groupby(By all rows), then spread it out, it still remain the same structure.

Do you know any way to make it happen? Thanks!

Transform.JPG

This is the Group By version:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKTylNLlFQ0lFyLi0uyc9NLTJEYhshsY2R2CZKsTrRSo5AEQM9kHoFOIaJK4DljFDEnXCod8KjXgEuZ4xVHCIHcY8zDvOdsZkfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Product ", type text}, {"Customer1", type number}, {"Customer2", type number}, {"Customer3", type number}, {"Customer4", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"Product "}, {{"Customer1", each List.Max([Customer1]), type number}, {"Customer2", each List.Max([Customer2]), type number}, {"Customer3", each List.Max([Customer3]), type number}, {"Customer4", each List.Max([Customer4]), type number}})
in
    #"Grouped Rows"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @ngct1112 ,

 

Just paste this code on Advanced Editor:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKTylNLlFQ0lFyLi0uyc9NLTJEYhshsY2R2CZKsTrRSo5AEQM9kHoFOIaJK4DljFDEnXCod8KjXgEuZ4xVHCIHcY8zDvOdsZkfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t, #"(blank).4" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}, {"(blank).4", type text}}),
#"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
#"Replaced Value" = Table.ReplaceValue(#"Promoted Headers",".",",",Replacer.ReplaceText,{"Customer1", "Customer2", "Customer3", "Customer4"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Customer1", type number}, {"Customer2", type number}, {"Customer3", type number}, {"Customer4", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Product "}, {{"Customer1", each List.Sum([Customer1]), type number}, {"Customer2", each List.Sum([Customer2]), type number}, {"Customer3", each List.Sum([Customer3]), type number}, {"Customer4", each List.Sum([Customer4]), type number}})
in
#"Grouped Rows"

 

Ricardo



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

Proud to be a Super User!



@camargos88 this is a smart and qucik way to do the transformance. this solve my problem. Great Thanks!! 

@ngct1112 ,

 

I glad it helped you.

 

If possible, please mark this as an solution and kudos.

 

Thanks,

 

Ricardo



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

Proud to be a Super User!



Helpful resources

Announcements
December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.