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
Anonymous
Not applicable

Pivoting with Multiple Values of The Same Type

Hi,

 

I've got this set of data in Power Query:

CASEIDTypeASSOCIATIONID
100000161Sales Order3010001838
100000161Sales Order3010003918
100000161Item1003706

 

But I'm trying to get to this solution:

CASEIDSales Order #1Sales Order #2Item #1
100000161301000183830100039181003706

 

How can I achieve this through Power Query?  I've tried using the Pivot and Unpivot functions, but these are not working.  Also, there will be instances where there are more than one Item and more than 2 sales orders.  TIA!

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this m code:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQAAUMzQyUdpeDEnNRiBf+ilNQiIM/YACRnaGFsoRSrQ1ihsaUhpkLPktRcIAUUMjY3MINIY+i3BAJipKCGGRsbK8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CASEID = _t, Type = _t, ASSOCIATIONID = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"CASEID", Int64.Type}, {"Type", type text}, {"ASSOCIATIONID", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"CASEID", "Type"},
{
{
"Rows", each
Table.CombineColumns(Table.TransformColumnTypes(
Table.AddIndexColumn(_, "Index", 1,1),
{"Index", type text}),
{"Type", "Index"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "Type2"),

type table [CASEID=number, Type2=text, ASSOCIATIONID=number]
}
}
),
#"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Rows"}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "Rows", {"CASEID", "Type2", "ASSOCIATIONID"}, {"CASEID", "Type2", "ASSOCIATIONID"}),
#"Pivoted Column" = Table.Pivot(#"Expanded Rows", List.Distinct(#"Expanded Rows"[Type2]), "Type2", "ASSOCIATIONID")
in
#"Pivoted Column"

 

Capture.PNG

 

 



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

Proud to be a Super User!



View solution in original post

2 REPLIES 2
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this m code:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQAAUMzQyUdpeDEnNRiBf+ilNQiIM/YACRnaGFsoRSrQ1ihsaUhpkLPktRcIAUUMjY3MINIY+i3BAJipKCGGRsbK8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CASEID = _t, Type = _t, ASSOCIATIONID = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"CASEID", Int64.Type}, {"Type", type text}, {"ASSOCIATIONID", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"CASEID", "Type"},
{
{
"Rows", each
Table.CombineColumns(Table.TransformColumnTypes(
Table.AddIndexColumn(_, "Index", 1,1),
{"Index", type text}),
{"Type", "Index"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "Type2"),

type table [CASEID=number, Type2=text, ASSOCIATIONID=number]
}
}
),
#"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Rows"}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "Rows", {"CASEID", "Type2", "ASSOCIATIONID"}, {"CASEID", "Type2", "ASSOCIATIONID"}),
#"Pivoted Column" = Table.Pivot(#"Expanded Rows", List.Distinct(#"Expanded Rows"[Type2]), "Type2", "ASSOCIATIONID")
in
#"Pivoted Column"

 

Capture.PNG

 

 



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

Proud to be a Super User!



Anonymous
Not applicable

Thank you, @camargos88 !  This did it!

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.