# Filter

The Filter tool allows users to filter any table based on an expression.&#x20;

| Selection             | Description                                                                                                                                                                                                                                                                                                          |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Filter Expression** | Build a boolean expression using Cascade [Expression Operators](https://docs.cascade.io/cascade/functions-and-expressions/building-expressions/expression-operators). Filter your selected table based off of any columns available.                                                                                 |
| **Limit** (optional)  | Limit prompt operates as a built in Sample tool. After filtering your data based on the expression prompt, users have the option of using the Limit prompt to reduce the size of the output table. For example, after filtering, enter "100" into the limit prompt to shrink the output table to the first 100 rows. |

### Filter Expression Configuration

Cascade's Expression Builder is a dynamic tool that is available in multiple tools throughout the platform. The Filter tool utilizes the expression builder to create custom filter logic using the selected table as well as any available variables.&#x20;

To build a Filter Expression, simply click into the expression box next to the `fx` and begin typing your expression logic. As you type, drop downs will appear to assist in autofilling functions, columns and variables that are available for use in the expression.&#x20;

<figure><img src="https://2577551913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MW_FvcY52Jcyt8JHFGs%2Fuploads%2FEUIemp12pBfryb7TqI5V%2Ftutorial01-step05.gif?alt=media&#x26;token=9f8a83fe-4c2a-4bc7-b6ba-f69eb4c34db3" alt=""><figcaption><p>Filter tables based on column values</p></figcaption></figure>

As seen in the graphic below, [Global Variables](https://docs.cascade.io/cascade/workflows/global-variables) can be used within Filter Expressions as dynamic variables. Simply start typing the name of your global variable in the Filter expression and it will show up as a selectable option in the dropdown list. &#x20;

<figure><img src="https://2577551913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MW_FvcY52Jcyt8JHFGs%2Fuploads%2FgKnYOO447oTBBrgfXfey%2Ffilter_GV.gif?alt=media&#x26;token=d1f1f2c0-e114-455d-b4a8-797af1cb9e85" alt=""><figcaption><p>Create a filter based on a Global Variable in your workflow</p></figcaption></figure>

{% hint style="info" %}
Once your table is filtered, use the "Limit" prompt to shrink your results to a desired sample size.
{% endhint %}

### Examples

#### Filter expressions can be equalities:

`{State} = "CA"`  -> All records with *state* **equal** to CA

`{State} != "CA"` -> All records with *state* **not equal** to CA

#### Or inequalities:

`{Population} > 1000000` -> All records with *population* **greater than** 1 million

`{Population} <= 1000000` -> All records with *population* **less than or equal** to 1 million

#### Conditions may also be combined:

`AND({State} = "CA", {Population} > 1000000)` << All records with *state* equal to CA **and** *population* greater than 1 million

`OR({State} = "CA", {Population} > 1000000)`<< All records with *state* equal to CA **or** *population* greater than 1 million

#### Or nested:

`AND(OR({State} = "CA", {State} = "NY"), {Population} > 1000000)` << All records with *state* equal to CA **or** NY, **and** *population* greater than 1 million

{% hint style="success" %}
Check out Cascade's full selection of functions available for use in the Filter Expression [here](https://docs.cascade.io/cascade/functions-and-expressions/functions).
{% endhint %}

### Outputs

Once you've completed your filter expression and have created your new filtered table, you'll notice two tabs available in the tool view:

<figure><img src="https://2577551913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MW_FvcY52Jcyt8JHFGs%2Fuploads%2FhE6BImEceunE8MpGb41l%2Fimage.png?alt=media&#x26;token=72618b1b-e7bb-4bab-a798-5a22e21e3187" alt=""><figcaption></figcaption></figure>

The first tab labeled `Filter - True` will show you the results for the desired filtered table based on your expression. The `Filter - False` tab will show you the data that was filtered out of your table in your expression. Both of these tables are available for use downstream in your workflow.&#x20;

<figure><img src="https://2577551913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MW_FvcY52Jcyt8JHFGs%2Fuploads%2FwywUZ0XtImfwWnHcsiA7%2Fimage.png?alt=media&#x26;token=e86de00e-49d9-4774-916a-b9d32f16cfef" alt=""><figcaption></figcaption></figure>

As you can see in the image above of a configured Filter tool, there are two output nodes. To use the `Filter - True` table, connect to the top right node, and to use the `Filter - False` table, connect to the bottom right node.&#x20;
