Learn how to filter a table based on NOT Contains Criteria. Download an example workbook here.
Easy step by step instructions below. See a single formula solution using the functions Splitter.SplitByAnyDelimiter, List.Count and Table.SelectRows. Amazing formula solution from Power Query Poet, Bill Szysz.
Please watch the video if you’d like for a guided walkthrough and also another method that can be useful for multiple tables.
Criteria Table
- Create a new, separate table with the list of terms you will want to exclude. Name the table “NoCriteria”.
- Add the excluded item (NoCriteria) table to Power Query – click within table, under Data menu, choose From Table/Range, which is in the Get and Transform data section.
- In the Power Query window, select the Transform menu and click convert to list.
- Under the File menu, choose Close and Load To, then choose Connection Only.
Building the Filtering via Power Query
- Add or create the list/table that will ultimately be filtered.
- Click any cell within the table that will be filtered. Add the excluded item table to Power Query (click within table, under Data menu, choose From Table/Range, which is in the Get and Transform data section).
- In the Power Query window, click the Add Column menu, and select Custom Column.
- In the window that opens, type this:
= Table.SelectRows(#”Changed Type”, each List.Count (Splitter.SplitTextByAnyDelimiter(NoCriteria)([PRODUCT_NAME]))=1)
- Change [PRODUCT_NAME] in that text to your own column in the table that you will be filtering on if it is different.
- Select the statement you have typed in and copy it (you will need to paste this formula in a following step).
- Click OK. You will see that the formula you typed was changed by the program and a column was added.
- To change the formula back, click the menu bar, highlight the entire text and then replace by pasting in the formula you copied. Hit enter.
- The extra column should be removed and the table should be filtered on you criteria from the NoCriteria table.
- Click the File menu, choose Close and Load To, then choose where you would like the newly filtered table loaded to.
Any time changes are made to the exclusion list, you will need to refresh the filtered table. Simply right click any cell within the filtered table, and select Refresh.
Bonus – Filtered table with the excluded items only (not shown in video)
You can additionally create a filtered table that only includes the terms in your NoCriteria table!
- To do this, go into Power Query. Right click on your filtered table and click Duplicate.
- In that new table, you will very slightly change the existing formula in your Power Query to not equal one (see orange text):
= Table.SelectRows(#”Changed Type”, each List.Count (Splitter.SplitTextByAnyDelimiter(NoCriteria)([PRODUCT_NAME]))<>1)
- Hit enter. The table should now only filter on the items in your exclusion list, instead of including them.
- Click the File menu, choose Close and Load To, then choose where you would like the newly filtered table loaded to.