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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BobKoenen
Helper IV
Helper IV

Convert rows from same customer into extra columns using PowerQuery

HI all, 

I am trying to do the opositie from a normal Pivot in Power Query but I cannot get it working. Hope you can help me. 

My data looks like this. 

Customer NumberAtribute AAtribute BAtribute C
1BottleSpikeHorse
1CapTriangleMoose
1WaterRoundDuck

 And I need it to look like this:

 

CustomernrABCA1B1C1A2B2

C2

1BottleSpikeHorseCapTriangleMooseWaterRoundDuck

 

My Table contains multiple Customers and a customer can have up to 10 rows which need to be converted into columns. (A10 B10 C10. I Hope you can help me fix this. 

 

Thanx in advance 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@BobKoenen , Try this in power Query

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLKLynJSQUyggsys0G0R35RcapSrA5E2jmxAEiGFGUm5qWDlfnm5yNJhyeWpBYB6aD80rwUIO1SmpytFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer Number" = _t, #"Atribute A" = _t, #"Atribute B" = _t, #"Atribute C" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer Number", Int64.Type}, {"Atribute A", type text}, {"Atribute B", type text}, {"Atribute C", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Customer Number", "Index"}, "Attribute", "Value"),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Index", type text}}, "en-US"),{"Attribute", "Index"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
#"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value", List.Max)
in
#"Pivoted Column"

View solution in original post

2 REPLIES 2
BobKoenen
Helper IV
Helper IV

@amitchandak 
Thankx a lot for replying. Unfortunatly I cannot use an index column because my data is a big table which has more than one customernumber 

CustomerNumerAC
1111Value AValue BValue C
1111Value AValue BValue C
1112Value AValue BValue C
1113Value AValue BValue C
1113Value AValue BValue C
1113Value AValue BValue C

Is there a way to use the index to count the number of rows from the same customer? Maybe that wil fix it. 

amitchandak
Super User
Super User

@BobKoenen , Try this in power Query

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLKLynJSQUyggsys0G0R35RcapSrA5E2jmxAEiGFGUm5qWDlfnm5yNJhyeWpBYB6aD80rwUIO1SmpytFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer Number" = _t, #"Atribute A" = _t, #"Atribute B" = _t, #"Atribute C" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer Number", Int64.Type}, {"Atribute A", type text}, {"Atribute B", type text}, {"Atribute C", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Customer Number", "Index"}, "Attribute", "Value"),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Index", type text}}, "en-US"),{"Attribute", "Index"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
#"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value", List.Max)
in
#"Pivoted Column"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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