Airtable API: How to find records with multiselect fields containing specific values among others?

I’m working with Airtable’s API and running into an issue with filtering multiselect fields. When I use the filterByFormula parameter, it only matches records where the field contains exactly the value I’m searching for, nothing more.

The problem is that I need to find records where a multiselect column includes my target string, even if it has other values selected too. My current approach is too restrictive.

Here’s what I’m currently using:

database('Products').select({
    view: 'All Items',
    filterByFormula: `Category = "${searchTerm}"`
}).firstPage(function(error, results) {
    if (error) { 
        console.error(error); 
        return error; 
    }

    results.forEach(function(item) {
        console.log(item.get('Product Name'));
    });
});

This code works fine for single-select fields, but with multiselect fields it’s not giving me the results I expect. I need a way to check if my searchTerm exists within the multiselect field, regardless of what other options might also be selected in that same field.

try using the FIND() function instead. something like FIND('${searchTerm}', ARRAYJOIN({Category})) > 0 should work for multiselect fields. the ARRAYJOIN converts your multiselect to a string so FIND can search thru it properly

Been dealing with this exact scenario for years. The SEARCH approach works but can give false positives if your search term appears inside another option name.

What I’ve found more reliable is using the REGEX_MATCH function:

filterByFormula: `REGEX_MATCH(ARRAYJOIN({Category}), "(^|,)${searchTerm}(,|$)")`

This pattern matches your search term only when it appears as a complete option, either at the start, end, or between commas. No more worrying about partial matches.

I learned this the hard way when searching for “Web” kept returning records with “Website Development” selected. The regex approach solved that issue completely.

Just make sure to escape any special regex characters in your searchTerm if you’re dealing with user input.

The issue you’re encountering is quite common when dealing with multiselect fields in Airtable. Instead of using direct equality, you need to leverage Airtable’s formula functions that can handle arrays. I’ve found that using the SEARCH() function with ARRAYJOIN() works reliably for this scenario. Your filterByFormula should look something like this: ```javascript
filterByFormula: SEARCH("${searchTerm}", ARRAYJOIN({Category}, ",")) >= 1