> ## Documentation Index
> Fetch the complete documentation index at: https://docs.allgoodhq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Filter a list with a formula

> Add a formula filter to a list when the built-in filters cannot say what you need, check the count, save your changes, and remove the filter.

A **formula filter** keeps a record in your list when its formula gives back true, and removes it when the formula gives back false. Use one when the built-in filters cannot express your question, such as "this **or** that," a number comparison, or a text match that ignores capitalization. This article walks you through adding a formula filter, checking that it works, and saving it.

## Prerequisites

* A list open in MK, such as your people or companies list.
* Permission to edit lists, if you plan to save your changes. You can try a formula without saving it.
* A formula to try. If you are new to formulas, read [What formulas are and when to use one](https://docs.allgoodhq.com/mk/formulas/what-formulas-are.md) first.
* The exact names of the fields you want to read. See [How formulas find your data](https://docs.allgoodhq.com/mk/formulas/how-formulas-find-your-data.md).

## How a formula filter works

MK works out your formula once for every record. If the answer is true, the record stays. If the answer is false, the record leaves. A formula filter works together with any built-in filters on the list. A record must pass all of them to stay.

Because the answer must be true or false, build your formula from comparisons and checks, such as `==`, `>=`, `exists()`, and `.includes()`.

## Steps

**1. Open your list**

Open the people or companies list you want to filter. The controls appear in the panel at the side of the list.

**2. Find the Filters section**

In the panel, find the **Filters** section. If the list has no filters yet, it reads "No filters — showing everything."

**3. Add a formula**

Select **+ ƒx**. A new row appears with an empty formula box.

**4. Type your formula**

Select the box and type your formula. For example, to keep people whose lifecycle stage is `lead` or `mql`:

```
$`person.lifecycleStage` == 'lead' || $`person.lifecycleStage` == 'mql'
```

Replace `lead` and `mql` with values from your own data.

**5. Apply the formula**

Press **Enter**, or select outside the box. MK applies the formula when you do either one, not while you type.

**6. Check the count**

Look at the count next to the list title and at the rows. The list now shows only the records where the formula gave true.

**7. Save your changes**

To keep the filter, select **Save**. If you are working on an unsaved view, select **Save view** instead. A saved list keeps its filters and columns.

You will see only the records that match your formula, and the count matches what you expect. If you saved, the filter appears in the list the next time you open it.

> [!NOTE]
>
> On a people list, saved lists may appear under the name **Segments**.

## Try these examples

Each formula below works on a people list and uses standard fields. Replace the values with ones from your own data.

| You want to keep | Formula |
| - | - |
| People with a title that contains "VP", in any capitalization, and an email | ``exists($`person.email`) && $`person.title`.toLowerCase().includes('vp')`` |
| People whose email ends in a work domain | ``exists($`person.email`) && $`person.email`.toLowerCase().endsWith('@acme.com')`` |
| People missing a first name or a last name | ``!exists($`person.firstName`, $`person.lastName`)`` |
| People with an email or a phone number | ``!empty($`person.email`, $`person.phone`)`` |

On a companies list, you can compare numbers:

| You want to keep | Formula |
| - | - |
| Companies with 500 or more employees | ``exists($`company.employeeCount`) && $`company.employeeCount` >= 500`` |
| Companies in one of two industries | ``$`company.industry` == 'Software' \|\| $`company.industry` == 'Finance'`` |

Here is how the first people example works out for three people.

| Title | Email | After |
| - | - | - |
| `'VP of Marketing'` | `'ana@acme.com'` | `true` (stays) |
| `'Director'` | `'ben@acme.com'` | `false` (leaves) |
| `'VP of Sales'` | No value | `false` (leaves) |

The check for an email comes first in these formulas on purpose. Without a check, a record with no value can pass a filter when you did not expect it. [Handle blank and messy values in formulas](https://docs.allgoodhq.com/mk/formulas/handle-blank-values.md) explains why.

## Change or remove a formula filter

* **To change it,** edit the text in the box, then press **Enter** or select outside the box.
* **To remove it,** select the remove button at the end of the formula row. The list goes back to showing the records the other filters allow.

Changes do not stay with the list until you select **Save**.

## If the list does not change

| What you see | What to check |
| - | - |
| The list did not change | Press **Enter** or select outside the box. MK applies a formula when you do. |
| MK shows an error message | The formula uses something MK does not support, or has a typo. Read the message. It points to the spot. |
| Every record disappeared | The formula gave false for every record. Check the field names and the values you compare against. |
| Records with blank fields stay in the list | Add an `exists()` check first. See [Handle blank and messy values in formulas](https://docs.allgoodhq.com/mk/formulas/handle-blank-values.md). |

For more causes and fixes, see [Formula gives a blank, wrong, or error result](https://docs.allgoodhq.com/mk/formulas/not-working.md).

## Related articles

* [What formulas are and when to use one](https://docs.allgoodhq.com/mk/formulas/what-formulas-are.md)
* [Add a calculated column to a list](https://docs.allgoodhq.com/mk/formulas/add-a-calculated-column.md)
* [Handle blank and messy values in formulas](https://docs.allgoodhq.com/mk/formulas/handle-blank-values.md)
* [Formula reference: concepts, functions, and operators](https://docs.allgoodhq.com/mk/formulas/reference.md)

If a formula filter gives an answer you cannot explain, contact allGood support. Include the formula, one record that should match and one that should not, and the full error message if there was one.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.