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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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