Dynamic Filtering in Google Sheets: Using a List to Filter a Range
Imagine you have a large dataset in Google Sheets and you want to filter it based on multiple criteria, each changing dynamically. You could manually filter each column one by one, but wouldn't it be great to have a single list that automatically updates your filter?
This is where dynamic filtering comes into play. It allows you to create a list of criteria and have your Google Sheet automatically filter based on those criteria. Here's how you can do it:
Scenario:
Let's say you have a list of products with their categories, prices, and availability in a Google Sheet. You want to filter this list based on specific categories and prices.
Original Code:
=FILTER(A:C, ISNUMBER(MATCH(B:B, {"Category 1", "Category 2"}, 0)))
Problem: This formula filters the data based on two specific categories. However, we need a way to make the criteria dynamic, allowing the user to add or remove categories without changing the formula.
Solution:
To create a dynamic filtering list, we'll use a combination of FILTER
, MATCH
, and INDIRECT
:
-
Create a List: On a separate sheet or a different section of your sheet, create a list of your filter criteria. For example, in a sheet called "Filters," you could have a column called "Categories" with the desired categories.
-
Dynamic Criteria: Use the
INDIRECT
function to reference your criteria list dynamically. This makes the filter criteria dynamic and allows you to change them without editing the formula.=INDIRECT("Filters!A2:A")
This formula refers to the range "A2:A" in the "Filters" sheet.
-
Filter the Range: Now, combine the
FILTER
,MATCH
, andINDIRECT
functions to filter your data.=FILTER(A:C, ISNUMBER(MATCH(B:B, INDIRECT("Filters!A2:A"), 0)))
This formula will filter the range "A:C" based on the categories listed in the "Filters" sheet.
Explanation:
INDIRECT("Filters!A2:A")
dynamically retrieves the list of categories from the "Filters" sheet.MATCH(B:B, INDIRECT("Filters!A2:A"), 0)
checks if each value in column "B" (categories) is present in the list of criteria from the "Filters" sheet.ISNUMBER(MATCH(...))
returns TRUE if a match is found and FALSE otherwise.FILTER(A:C, ISNUMBER(MATCH(...)))
filters the range "A:C" based on the results of the MATCH function, including only rows where a match is found.
Advantages:
- Dynamic and Flexible: You can easily modify your filter criteria by simply editing the list in the "Filters" sheet.
- User-Friendly: Allows users to update the filter criteria without needing to understand the formulas.
- Re-usable: You can apply this approach to filter any range using a dynamic criteria list.
Practical Example:
Let's say you have a list of products in sheet "Products" (A:C) and you want to filter them by category and price. In sheet "Filters," you have two columns: "Categories" (A) and "Price Range" (B).
You can use the following formula to filter the products:
=FILTER(Products!A:C,
ISNUMBER(MATCH(Products!B:B, INDIRECT("Filters!A2:A"), 0)) *
(Products!C:C >= INDIRECT("Filters!B2") * Products!C:C <= INDIRECT("Filters!B3")))
This formula will filter the products in "Products" based on the categories listed in "Filters!A2:A" and prices within the range defined by "Filters!B2" and "Filters!B3".
Key Takeaway:
Dynamic filtering with INDIRECT
offers a powerful solution to create flexible and user-friendly filtering solutions in Google Sheets. It allows you to easily adapt your filters based on changing needs and provides a much more efficient approach than manually filtering each column.
Further Exploration:
For more advanced filtering scenarios, you can explore using the QUERY
function, which allows you to specify more complex filter conditions using SQL-like syntax.
By understanding and applying these techniques, you can transform your Google Sheets into dynamic and interactive data analysis tools.