Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Salesforce Filter Logic Operators: How to Use AND, OR, NOT

· 8 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Salesforce filter logic operators let you combine conditions in a report, list view, or dashboard filter so that only the records you actually want come back. Instead of stacking filters and hoping the AND behaviour works out, you write a small expression such as 1 AND (2 OR 3) that tells Salesforce exactly how to treat each filter row. The operators you work with are AND, OR and NOT, plus parentheses for grouping. You need nothing beyond normal access to Reports, List Views or the filter panel you are editing, and the filter rows already added to the object you are querying.

What You'll Need

  • A Salesforce account with permission to create or edit reports, list views or dashboards. Filters you cannot save are usually a permission or folder access issue, not a logic issue.
  • Two or more filter rows already added to the report or list view. Filter logic refers to rows by number, so the rows must exist before you write the expression.
  • A clear idea of which records should be included, written in plain language first. The logic is only as good as the conditions it points at.
  • Access to both the Filters panel and the filter logic text box. In Reports this is in the Filters pane under the row list; in List Views it sits with the filter rows as well. Labels vary slightly by Salesforce release, edition and Lightning versus Classic, so look for the filter logic field near the filter rows if the wording differs.

Step-by-Step

  1. Open the report or list view you want to filter. For a report, open Reports, choose the report and click Edit. For a list view, open the object tab, pick the list view from the dropdown and click Edit next to the view name. Filter logic belongs to the view or report, so editing the right one matters.
  2. Add your filter rows first, one condition each. Each row is a single field, operator and value, for example Stage equals Closed Won in row 1, Amount greater than 10000 in row 2, Owner equals a specific user in row 3. Keep each row to one idea so the logic stays readable.
  3. Note the row numbers. Salesforce numbers filter rows from the top of the Filters panel. Adding, deleting or reordering rows changes those numbers, so write your expression after the rows are final and re-check the numbering if you move anything. Blank rows are skipped in numbering, so a gap in the list does not automatically add a number.
  4. Find the filter logic field. In Reports, expand the Filters pane and look for the filter logic option below the row list. In List Views, the same field appears with the filter criteria. It defaults to 1 AND 2 AND 3 and similar, which means every row must be true.
  5. Replace the default with your expression. Use row numbers, the three operators and parentheses. A typical example is 1 AND (2 OR 3), which means row 1 must be true and at least one of rows 2 or 3 must also be true. Another common pattern is (1 OR 2) AND NOT 3, which excludes anything matching row 3.
  6. Use AND for narrowing. 1 AND 2 returns records that satisfy both conditions. Reach for AND when you want fewer, more specific records, for example open opportunities owned by a single team above a value threshold.
  7. Use OR for widening. 1 OR 2 returns records that satisfy either condition, including records that satisfy both. Reach for OR when you want a union, for example records with one status or another.
  8. Use NOT to exclude. 1 AND NOT 2 returns records that match row 1 but do not match row 2. NOT is the cleanest way to say unless or excluding, and it reads better than trying to build the inverse condition inside a row.
  9. Group with parentheses. Parentheses control which conditions are evaluated together. 1 AND 2 OR 3 is not the same as 1 AND (2 OR 3), so add brackets whenever the intent is anything other than a straight chain. When in doubt, group more rather than less.
  10. Validate the syntax. Click the validation or run option, or simply run the report. Salesforce rejects expressions with unbalanced parentheses, a number that does not match an existing row, or two operators in a row. Fix the error message shown on screen before saving.
  11. Check the results against expectations. Compare the record count with the count you got before applying logic. If the number looks wrong, temporarily simplify to a single row, confirm it returns sensible records, then add conditions back one at a time.
  12. Save the report or view. Save with your changes so the logic persists. For reports, save into a folder you and your audience can access; for list views, choose who it is shared with.

Common Mistakes

  • Leaving the default logic in place. Salesforce fills the field with a simple AND chain of every row. If you add an OR-style condition but never edit the logic, the new row is still joined by AND and narrows the results instead of widening them.
  • Forgetting parentheses. Mixing AND and OR without grouping produces an expression whose meaning is easy to misread. Even where Salesforce accepts it, add brackets so the intent is explicit and future editors do not break it.
  • Row numbers out of step with the rows. Deleting a filter row renumbers everything below it. An expression that still points at row 3 may now point at a different condition or at nothing, producing an error or quietly wrong results.
  • Referencing a row that does not exist. Using 4 with only three filter rows returns a validation error. Add the row first, then reference it.
  • Trying to filter a field that is not filterable. Some fields, including certain long text and formula fields, cannot be used as filter criteria. Filter logic cannot rescue a row that the field itself does not support; choose a different field.
  • Using NOT on the wrong row. NOT 1 AND 2 excludes records that match row 1 and keeps those matching row 2, which is usually the opposite of what was intended. Group it as 2 AND NOT 1 if you mean exclude row 1 from row 2 results.
  • Assuming list view logic carries into reports. Each report and each list view has its own logic. Editing one does not change the other, even when they show the same object.

Tips

  • Write the plain-English rule first, then translate it. For example, closed won above ten thousand owned by Ana or Ben becomes 1 AND 2 AND (3 OR 4) with rows for stage, amount, Ana and Ben.
  • Build in layers. Get one row returning the right records, then add the next row and the operator together, checking the count each time.
  • Keep your expressions short and evenly parenthesised. Deep nesting works but becomes hard to audit when someone else edits the report later.
  • Use NOT rather than long lists of every other value. Excluding the one value you do not want is more maintainable than OR-ing together all the values you do.
  • Put a descriptive name on filters where the option exists, and add a report description explaining the logic, so the next person does not have to reverse-engineer it.
  • Remember that filter logic combines with other report features. Cross filters, grouping filters and dashboard filters each apply on top, so check the whole report rather than the filter pane alone when totals look strange.

Troubleshooting

If Salesforce will not accept the expression, read the error text carefully. It usually names the problem: malformed logic, an unexpected number, or parentheses that do not pair up. Recount the rows and rebuild the string from scratch in a scratch pad before pasting it back.

If the expression is accepted but the results are wrong, test each row on its own. Temporarily set the logic to 1, run it, then 2, and compare counts with your expectations. If a single row returns nothing, the problem is the row's field, operator or value, not the logic.

If the report returns too many records, check that the default AND chain was actually replaced and that your OR groups are parenthesised. If it returns too few, look for a stray AND joining something that should have been inside an OR group.

If a colleague sees different results, check sharing and folder access, running user settings for dashboards, and whether they are looking at the same saved version. Filter logic does not override record-level sharing; it only narrows what the running user can already see.

If saving fails, confirm you have edit rights on the report folder or list view, and check whether the report is in a read-only folder or a package you cannot change. Copy it to your own folder and edit the copy instead.

Frequently Asked Questions

What operators can I use in Salesforce filter logic?

AND, OR and NOT, combined with parentheses and filter row numbers. That is the full set for report and list view filter logic.

Is AND evaluated before OR?

Do not rely on a default order. Parentheses control evaluation, so group conditions explicitly and the expression will behave the same way every time regardless of how it is read.

Can I reference the same filter row twice?

You can use a row number more than once in an expression, but that is a sign the logic needs simplifying. Duplicating a row's number rarely changes the meaning and makes the expression harder to maintain.

Does filter logic work the same in Lightning and Classic?

The operators and syntax are the same, but the location and wording of the filter logic field differ between interfaces and releases. Look for it near the filter rows if the label is not exactly as described.

Why does my report ignore my filter logic?

The most common cause is that the logic was edited but the report was not saved, or a dashboard filter or cross filter is further narrowing the data on top of the report logic.

Can filter logic include fields from related objects?

Only where the report already supports a filter on that related field. If the row cannot be created for that field, logic cannot make it filterable; add the relationship through the report type or use a cross filter instead.