Forum Discussion
uc
5 years agoHelper II
To transpose data in power query editor
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
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 SplitSource
Result
2 Replies
- JakintaSolution Sage
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 SplitSource
Result
- ucHelper II
Thankyou for your quick response.