# How to use filter logic in lead assignment rules

When building a lead assignment rule with more than two filter rows, you might add filters with both AND and OR operators between them. In those situations, you'll need to use the Filter Logic field to make sure your rule matches the right leads.

Let's look at an example of how to use filter logic:

We have two salespeople on our sales team, Ray Tomlinson and Alex Bell, who deal with leads from the states of Massachusetts and Rhode Island. Ray handles leads via email, and Alex reaches out to leads by phone. When leads have both a phone number and an email address, they are to be distributed to Ray and Alex in a turn-based, round-robin fashion.

As we build our lead assignment rule, we'd use these filters:

1. Phone is not empty
AND
2. Email is not empty
AND
3. State/Province = RI
OR
4. State/Province = MA

The problem here is that the last OR will capture all the leads from Massachusetts, whether they have email addresses and phone numbers or not, which is not what we want. With filter logic, we can get different results by grouping (or "nesting") the filters.

## Applying filter logic in your assignment rule

1. We add filters to our criteria as we set up a new rule. Notice that the filters are numbered on the left. We'll use these numbers in the Filter Logic formula bar.
2. Click the Add Filter Logic link. This link will appear when you have more than two filter rows.
3. Edit the logic in the formula bar by adding parentheses or changing the operators. In this case, we'll add parentheses around the first two arguments, changing "1 OR 2 AND 3 AND 4" to "(1 OR 2) AND 3 AND 4" to find the right matches.
4. Click the Save Criteria button to save your changes.
5. We can now continue with setting up this set of criteria and assigning it to both Alex and Ray.

Now, when we receive leads from either state (MA OR RI) that include both a phone number and an email address (AND Email AND Phone), the first will be assigned to Alex, the second to Ray, the third to Alex, and so on.

Nested filters

As you add more filters to your criteria, your formulas can become even more complex. Rule criteria with five filters can have many different combinations, depending on where you add parentheses:

(1 AND 2) OR (3 AND 4) OR 5
1 AND ((2 AND 3) OR 4 OR 5)
((1 AND 2) OR (3 OR 4)) AND 5

Placing parentheses within parentheses is called nesting. The important thing to remember with nesting is that Insightly will process the arguments in the innermost parentheses first and work outward.

As you enter more complex filter logic, examine the formula one step at a time, verifying each argument within a set of parentheses.