Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello
I have got a table which has more than one contact number for each id. This is shown in table 1 as below.
Table 1
ID | Telecom Number | DOB |
1 | 01522 7876543 | 01/01/2000 |
1 | 0789654321 | 01/01/2000 |
2 | 01323 7652341 | 04/05/2000 |
2 | 0798712345 | |
2 | 0798712345 | 04/05/2000 |
3 | 05/04/1990 | |
3 | 01522 5678976 | 05/04/1990 |
3 | 0789765432 | |
I want to re order the table 1 as below as in table 2
Table 2
ID | Telcom number 1 | Telcom Number 2 | DOB |
1 | 01522 7876543 | 0789654321 | 01/01/2000 |
2 | 01323 7652341 | 0798712345 | 4/05/2000 |
3 | 01522 578976 | 0789765432 | 05/04/1990 |
Is this possible in power query? Please advise. Thanks in advance
Solved! Go to Solution.
Please see below. I tried to make it dynamic in case you don't have unifom Telecom Number counts per ID.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY5LDoAgDAWvQro2oR9K4SyG+1/DUo0mqAkLOvOgb9+BYAMkZU7WrGqRmLMfRkQY2xWx1qdlensOJCzJP2ApESkZdYlYb0bu1Yf0jZdnEknHmt1Q7w8+O2v1XlZ/IuFm6XvhxLGrmt9gjAM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Telecom Number" = _t, DOB = _t]),
Trim = Table.TransformColumns(Source,{{"Telecom Number", Text.Trim, type text}, {"DOB", Text.Trim, type text}}),
Group = Table.Group(Trim, {"ID"}, {{"Gr", each Text.Combine(List.RemoveMatchingItems(List.Distinct(_[Telecom Number]), {""}) ,"|")}, {"DOB", each List.RemoveMatchingItems(List.Distinct([DOB]),{""}){0}}}),
Count = {1..List.Max(List.Transform(Group[Gr], each List.Count(Text.Split(Text.From(_),"|"))))},
Split = Table.SplitColumn(Group, "Gr", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), List.Transform(Count, each "Telecom Number " & Text.From(_)) )
in
Split
Source
Result
Please see below. I tried to make it dynamic in case you don't have unifom Telecom Number counts per ID.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY5LDoAgDAWvQro2oR9K4SyG+1/DUo0mqAkLOvOgb9+BYAMkZU7WrGqRmLMfRkQY2xWx1qdlensOJCzJP2ApESkZdYlYb0bu1Yf0jZdnEknHmt1Q7w8+O2v1XlZ/IuFm6XvhxLGrmt9gjAM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Telecom Number" = _t, DOB = _t]),
Trim = Table.TransformColumns(Source,{{"Telecom Number", Text.Trim, type text}, {"DOB", Text.Trim, type text}}),
Group = Table.Group(Trim, {"ID"}, {{"Gr", each Text.Combine(List.RemoveMatchingItems(List.Distinct(_[Telecom Number]), {""}) ,"|")}, {"DOB", each List.RemoveMatchingItems(List.Distinct([DOB]),{""}){0}}}),
Count = {1..List.Max(List.Transform(Group[Gr], each List.Count(Text.Split(Text.From(_),"|"))))},
Split = Table.SplitColumn(Group, "Gr", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), List.Transform(Count, each "Telecom Number " & Text.From(_)) )
in
Split
Source
Result
Thankyou for your quick response.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.