Pattern: Contains Operator for Data Table Filter

Oftentimes you need to check to see if a text-type column contains a substring of text anywhere in the cell. To do this, you need to write a formula using the Tables: Apply formulas to columns action, leveraging the JavaScript includes() method.

The attached workflow has an associated data table that looks like this:

Column A,Column B
111,22Red100
888,43Green800

It allows you to select a color and check Column B to see if the color selection is present anywhere in the string. If it is, you get a filtered table in the Filter Contains column for True values step.

Comments

  • Hi,

    I'm trying to use the recommended pattern build above, however, I needed to return two different types of values rather just one. How will the javascript need to be modified to get this result?

  • Jozef_783863
    Jozef_783863 Posts: 331 admin

    Hi @Fredrick_934104, Welcome to the Community and thank you for your first comment!

    I recently needed Tables: Apply formulas to columns to set a column to "True" if column 1 had more than one matching criteria. Below is the formula from my particular case that should help when you need more than one matching criteria. Although I am not a Javascript expert, I found that this returned the results I needed.

    if (columns["Column 1"].includes("<td class=")) {
    columns["Filter"] = "True" }
    else if (columns["Column 1"].includes("<table")) {
    columns["Filter"] = "True" }
    else if (columns["Column 1"].includes("</table>")) {
    columns["Filter"] = "True" }
    else if (columns["Column 1"].includes("<tr>")) {
    columns["Filter"] = "True" }
    else if (columns["Column 1"].includes("</tr>")) {
    columns["Filter"] = "True" }
    else {
    columns["Filter"] = "False" }