Forum Discussion
How to filter a column based on a column from another table?
I have Table 1 that contains a column of ALL of my employees:
| Employee ID | Sales Value |
| 1 | 25 |
| 2 | 50 |
| 3 | 75 |
| 4 | 100 |
| 5 | 100 |
I have Table 2 that contains a SUBSET of employees and their info:
| Employee ID | First Name | Last Name |
| 2 | Jon | Doe |
| 4 | Jane | Doe |
I want to filter my Table 1, so that it only contains rows that show up in Table 2. Table 1 after the filter should look like this:
| Employee ID | Sales Value |
| 2 | 50 |
| 4 | 100 |
How do I achieve this? Bonus: is there a way to achieve this without doing a Join? The tables are millions of rows long, so I don't know how join would impact performance.
Hi Anonymous
An inner join should do it and is quite probably the best performing option
Place the following M code in a blank query to see the steps.
let Source = Table.NestedJoin(Table1, {"Employee ID"}, Table2, {"Employee ID"}, "Table2", JoinKind.Inner), #"Removed Columns" = Table.RemoveColumns(Source,{"Table2"}) in #"Removed Columns"Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
2 Replies
- AlBCommunity Champion
Hi Anonymous
An inner join should do it and is quite probably the best performing option
Place the following M code in a blank query to see the steps.
let Source = Table.NestedJoin(Table1, {"Employee ID"}, Table2, {"Employee ID"}, "Table2", JoinKind.Inner), #"Removed Columns" = Table.RemoveColumns(Source,{"Table2"}) in #"Removed Columns"Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
- IceyCommunity Support
Hi Anonymous ,
You can also try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyVYrViVYyAjJNDcBMYyDTHCJqAmQaGkCETWHsWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Sales Value" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", Int64.Type}, {"Sales Value", Int64.Type}}), #"Filtered Table1" = Table.SelectRows(#"Changed Type", each List.Contains(#"Table2"[Employee ID],[Employee ID])) in #"Filtered Table1"Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.