Salesforce Filter Logic: How to Write It
In this article
Filter logic in Salesforce lets you combine up to 99 filter conditions with AND, OR, and NOT so a report, list view, or dashboard component returns exactly the records you want. You write it by numbering each filter row and then referencing those numbers in the logic box, for example 1 AND (2 OR 3). The numbered rows appear in the order you add them, and the logic box evaluates those numbers, not the field names.
What You'll Need
- A Salesforce account with permission to create or edit reports, list views, or dashboard components.
- The object you want to filter (Accounts, Opportunities, Contacts, Cases, and so on) and the fields you plan to use.
- At least two filter rows in place before the logic box becomes useful. One row does not need logic.
- A clear idea of the records you want to include and the ones you want to exclude.
Step-by-Step
- Open the report, list view, or dashboard component you want to filter. For a report, go to Reports and open or create the report. For a list view, open the object tab and choose New List View or edit an existing one. Menu labels can differ slightly by Salesforce version and edition.
- Add your filter rows first. In a report, open the Filters panel and add each condition (field, operator, value). In a list view, use the Filter By section. Each row you add gets a number, starting at 1, in the order it appears.
- Decide which rows are alternatives and which are requirements. Rows that must all be true are joined with AND. Rows where any one is enough are joined with OR. Rows you want to exclude are wrapped in NOT.
- Write the logic in the filter logic box. Use the row numbers and the operators AND, OR, NOT, and parentheses. For example, if row 1 is a required condition and rows 2 and 3 are alternatives, write
1 AND (2 OR 3). If rows 1 and 2 are alternatives and row 3 is required, write(1 OR 2) AND 3. - Use parentheses to control order. Salesforce evaluates what is inside parentheses first, then AND, then OR, unless parentheses say otherwise. When in doubt, add parentheses rather than relying on default precedence.
- Check that every row number you reference exists. If you delete a filter row, the numbers of the rows below it shift, and the logic box will show an error or behave unexpectedly until you update it.
- Click Run or Save. Salesforce validates the logic and shows an error if the syntax is wrong, such as a missing parenthesis or an unknown row number.
- Review the results against a record you know should be included and one you know should be excluded. If either is wrong, adjust the operators or parentheses and run again.
Common Mistakes
- Referencing a row number that no longer exists after deleting or reordering filters. Always recheck the logic box after changing rows.
- Forgetting parentheses around OR groups.
1 AND 2 OR 3is not the same as1 AND (2 OR 3). - Using AND when OR was intended, which narrows results to almost nothing.
- Leaving the logic box blank when you meant to combine rows. A blank box means all rows are joined with AND by default.
- Using NOT without parentheses, which can invert more than intended. Write
NOT (1 OR 2)rather thanNOT 1 OR 2. - Assuming filter logic works on every filter type. Some filters, such as certain date filters or scope filters, are applied outside the logic and cannot be referenced by number.
Tips
- Build the logic in small pieces. Start with two rows, confirm the result, then add the next row and update the logic.
- Name your intent before writing: for example, "all open cases owned by my team, excluding escalated ones." That translates directly into rows and operators.
- Keep the logic box readable by grouping related rows with parentheses even when precedence would give the same result.
- Test with a report that shows the filter rows and a few sample records so you can see which rows are matching.
- If the logic gets long, split the report into two reports and combine them in a dashboard rather than building a single complex filter.
Troubleshooting
If Salesforce shows a syntax error, check for a missing or extra parenthesis, a comma where an operator belongs, or a row number that does not exist. If the report runs but returns no records, temporarily remove the logic and confirm the rows themselves return data, then add the logic back one operator at a time. If results are broader than expected, check whether an OR group is missing parentheses. If a filter row seems ignored, confirm it is a row that filter logic can reference; some filters are applied separately. If the logic box is greyed out, you likely have only one filter row, so add another. If you cannot save, confirm you have permission to edit the report or list view, and check whether the report is in a folder you can modify.
Frequently Asked Questions
What is filter logic in Salesforce?
It is a way to combine numbered filter conditions with AND, OR, and NOT so a report, list view, or dashboard component returns a specific set of records.
How many filter conditions can I combine?
Salesforce reports support up to 99 filter conditions, and the logic box can reference any of them by number.
Do I need parentheses?
Not always, but they make the order of evaluation explicit and prevent mistakes when AND and OR are mixed.
Why did my report return no records after adding logic?
Usually an AND was used where OR was intended, or a row number points to a filter that excludes everything. Remove the logic, test the rows, then rebuild it.
Does filter logic work on list views?
Yes, list views have a filter logic box that works the same way, referencing the numbered filter rows in that list view.
What happens if I delete a filter row?
The remaining rows renumber, so the logic box may reference the wrong row or show an error. Update the logic after any row change.