Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe 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.
Hi,
I've got this set of data in Power Query:
CASEID | Type | ASSOCIATIONID |
100000161 | Sales Order | 3010001838 |
100000161 | Sales Order | 3010003918 |
100000161 | Item | 1003706 |
But I'm trying to get to this solution:
CASEID | Sales Order #1 | Sales Order #2 | Item #1 |
100000161 | 3010001838 | 3010003918 | 1003706 |
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!
Solved! Go to Solution.
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"
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"
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
82 | |
78 | |
52 | |
39 | |
35 |
User | Count |
---|---|
94 | |
79 | |
51 | |
47 | |
47 |