I’m working with Airtable’s API and trying to use the filterByFormula parameter to find records. My issue is with multiselect field types where I want to match records that include a particular value, even if they have other values selected too.
Right now my filter only finds exact matches, not partial matches within multiselect fields. I need to find records where my target string exists alongside other possible selections in the same field.
Here’s my current approach:
database('MyTable').select({
view: 'Primary View',
filterByFormula: `Category = "${searchTerm}"`
}).firstPage(function(error, results) {
if (error) {
console.error(error);
return error;
}
results.forEach(function(item) {
console.log(item.get('Title'));
});
});
This code works fine for single-select fields, but with multiselect columns it only returns records where my searchTerm is the only selected option. I want it to also return records where searchTerm is one of several selected values.
How can I modify the filterByFormula to check if a multiselect field contains my target value among its selections?
Use FIND() instead of equals. Try FIND("${searchTerm}", ARRAYJOIN({Category})) > 0
- it’ll catch partial matches in multiselect fields. Works great for tags and categories.
The previous suggestions work, but SEARCH and FIND killed performance on my larger tables. I switched to OR() function - way more efficient for checking combinations:
filterByFormula: `OR(FIND("${searchTerm}", ARRAYJOIN({Category}, ",")) > 0)`
Cut my query times dramatically vs string manipulation. Here’s another trick - use SUBSTITUTE for exact matching without comma workarounds:
filterByFormula: `SUBSTITUTE(ARRAYJOIN({Category}), "${searchTerm}", "") != ARRAYJOIN({Category})`
Basically checks if removing your search term changes the string. If it does, the term was there. Works great for partial matches in multiselect fields and avoids false positives from substring matches.
Been dealing with this exact issue for years. FIND works but gives false positives when your search term shows up inside other options.
I use SEARCH with comma separators:
filterByFormula: `SEARCH(",${searchTerm},", "," & ARRAYJOIN({Category}, ",") & ",") > 0`
This wraps the array with commas and searches for your term with commas on both sides. Stops partial word matches.
Search for “Tech” and it won’t grab “FinTech” anymore.
You can also use regex if you need more control:
filterByFormula: `REGEX_MATCH(ARRAYJOIN({Category}), "${searchTerm}")`
I stick with the comma method - handles edge cases better and runs faster on big datasets.