Forum Discussion
Power Query: Filter table based on list with wildcards
- Jun 05, 2021
As variant, if you would like to filter first table on the texts in the second table from which first table text start
the query could be like
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Added Custom" = Table.AddColumn( Source, "Custom", each [a=[A], b=List.Contains( List.Transform( Table2[B], each Text.StartsWith(a, _) ), true ) ][b] ), #"Filtered Rows" = Table.SelectRows( #"Added Custom", each ([Custom] = true) ), #"Removed Other Columns" = Table.SelectColumns( #"Filtered Rows", {"A"} ) in #"Removed Other Columns"
List.Transform checks if for any element of second table column A starts from it. With List.Contains we check if there are at least one TRUE. Finally filter on this column and remove it.
- Crafting4USep 18, 2021Copper ContributorWill this filter Rows, or just Cells?
- SergeiBaklanSep 18, 2021Diamond Contributor
Not sure I understood the question. In general in PQ we operate with records (aka rows in tables) and lists (aka columns in tables), what do you mean under filtering of cells?
- Crafting4USep 18, 2021Copper ContributorI think that confirms that my fear is unfounded. In Excel, if I select a range and delete, I must decide how adjacent cells will shift to fill in, effectively changing an order of 3 blue widgets to an order of 1125 yellow turtles.
- bartvanaJun 05, 2021Iron ContributorYes, but I want it to fetch the "begins with" string from another table... How could that be done?
- SergeiBaklanJun 05, 2021Diamond Contributor
As variant, if you would like to filter first table on the texts in the second table from which first table text start
the query could be like
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Added Custom" = Table.AddColumn( Source, "Custom", each [a=[A], b=List.Contains( List.Transform( Table2[B], each Text.StartsWith(a, _) ), true ) ][b] ), #"Filtered Rows" = Table.SelectRows( #"Added Custom", each ([Custom] = true) ), #"Removed Other Columns" = Table.SelectColumns( #"Filtered Rows", {"A"} ) in #"Removed Other Columns"
List.Transform checks if for any element of second table column A starts from it. With List.Contains we check if there are at least one TRUE. Finally filter on this column and remove it.
- bartvanaJun 07, 2021Iron ContributorYes, thank you, that's exactly what I needed.
- SergeiBaklanJun 05, 2021Diamond Contributor
Another table could have a lot of records. Would you like to filter on "begin with" for all of them or for some specific records?