Forum Discussion
Merge tables 2 columns matching 1
- 3 years ago
Hi GP85 ,
According to your description, here's my solution. Add a step in Table1 Advanced editor:
#"New"=let filter=Table.SelectRows(Table2,each [Department]="Department 1") in Table.SelectRows(#"Changed Type",each List.Contains(filter[Portfolio],[Portfolio]) or List.Contains(List.RemoveNulls(filter[Security]),[Security]))Result:
Here's the whole M syntax:
Table2:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsgvKknLz8nMVzBU0lFySS1ILCrJTc0rUTAHcoNTk0uLMksqgXKxOshqjVDVmgG5aCqMUVUYYqowwVQBt88ITa0pqlojTNPMCKowR1VhjKnCgqAKS1QVpshuNkZTa2hAMAgMDQnaaIgW1CbIVpqiK8YS6nDFJkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Portfolio = _t, Department = _t, Security = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Portfolio", type text}, {"Department", type text}, {"Security", type text}}) in #"Changed Type"Table1:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsgvKknLz8nMVzBU0lFSUIrVQRYzwiJmCRQLTk0uLcosqQQqQJU0RJY0RJdEkTVFkzUnZJcJmqQFFg2GBhDBWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Portfolio = _t, Security = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Portfolio", type text}, {"Security", type text}}), #"New"=let filter=Table.SelectRows(Table2,each [Department]="Department 1")in Table.SelectRows(#"Changed Type",each List.Contains(filter[Portfolio],[Portfolio]) or List.Contains(List.RemoveNulls(filter[Security]),[Security])) in #"New"I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi GP85
You'll probably need to do some kind of table join but hard to say exactly without seeing your data and knowing exactly what the result you want is. Can you please provide both?
Regards
Phil
Hi PhilipTreacy
Thanks for your message.
From this table I would like to keep only records where either Portfolio or Security belongs to Department 1:
| Portfolio | Security |
| Portfolio 1 | |
| Portfolio 2 | |
| Portfolio 9 | Security 2 |
| Portfolio 1 | Security 1 |
| Portfolio 11 | Security 5 |
| Portfolio 7 | |
| Portfolio 9 | Security 4 |
| Portfolio 8 | |
| Portfolio 10 |
Based on the below table:
| Portfolio | Department | Security |
| Portfolio 1 | Department 7 | Security 1 |
| Portfolio 2 | Department 6 | |
| Portfolio 3 | Department 1 | |
| Portfolio 4 | Department 1 | Security 2 |
| Portfolio 5 | Department 2 | |
| Portfolio 6 | Department 2 | |
| Portfolio 7 | Department 3 | |
| Portfolio 8 | Department 3 | |
| Portfolio 9 | Department 5 | Security 3 |
| Portfolio 10 | Department 1 | |
| Portfolio 11 | Department 3 | |
| Portfolio 12 | Department 4 | Security 5 |
| Portfolio 13 | Department 1 | Security 4 |
End result from the Table 1 should be following:
| Portfolio | Security |
| Portfolio 9 | Security 2 |
| Portfolio 9 | Security 4 |
| Portfolio 10 |
Portfolio 9 holging Securities 2 and 4 that belong to Department 1
Portfolio 10 that belongs to Departmenet 1.
Hope that helps.
Many thanks