# When to use AND vs. OR logic?

### Introduction

Creating effective filters in HockeyStack requires a solid understanding of AND/OR logic. While these concepts might seem complex at first, this guide will help you master them through clear examples and practical scenarios.

### Basic Concepts

#### AND Logic

When using AND logic, **all** conditions in the statement must be true for a filter to match.

**Example:**

```
Filter: User is from Canada AND has made a purchase
```

A user will only match this filter if they meet both conditions:

* They are from Canada
* They have made a purchase

#### OR Logic

When using OR logic, **at least one** condition must be true for a filter to match.

**Example:**

```
Filter: User is from Canada OR has made a purchase
```

A user will match this filter if they meet either condition:

* They are from Canada
* They have made a purchase

### Real-World Example: North America Filter

Let's follow a practical example with a user named Michael Scott who is from the US

#### Scenario 1: Filter for North American Users

To create a filter for North American users, we would use:

```
Filter: User is from Canada OR User is from US
```

For Michael:

* ❌ User is from Canada = FALSE
* ✅ User is from US = TRUE
* **Result:** **CORRECT:** Filter matches (TRUE) because one condition is met

#### Scenario 2: Filter for Non-North American Users (Common Mistake)

```
Filter: User is NOT from Canada OR User is NOT from US
```

For Michael:

* ✅ User is NOT from Canada = TRUE
* ❌ User is NOT from US = FALSE
* **Result:** **INCORRECT:** Filter incorrectly matches (TRUE) because one condition is met

```
Filter: User is NOT from Canada AND User is NOT from US
```

For Michael:

* ✅ User is NOT from Canada = TRUE
* ❌ User is NOT from US = FALSE
* **Result:** **CORRECT:**&#x46;ilter correctly doesn't match (FALSE) because both conditions aren't met

### Advanced Usage: LinkedIn Ads Visits Filter

When creating complex filters, such as for LinkedIn Ads visits, you have two approaches for structuring your filters:

#### Option 1: Bottom-Level AND

```
UTM Source = linkedin OR
UTM Source = linkedin.com
    AND Touchpoint Type = Website Session
```

#### Option 2: Top-Level AND (Recommended)

```
(UTM Source = linkedin OR UTM Source = linkedin.com)
AND
Touchpoint Type = Website Session
```

The second approach is more scalable because:

* It reduces redundancy
* Makes it easier to add new conditions
* Maintains cleaner filter logic

#### 💡 Pro Tip

When building complex filters, start with your OR conditions grouped together, then use the "Switch And/Or" feature to add common conditions at the top level. This approach makes your filters more maintainable and easier to update.

### Best Practices

1. Always test your filters with known data to verify they're working as expected
2. Group related OR conditions together
3. Use top-level AND for conditions that apply to all criteria
4. Double-check your logic when using NOT operators
5. Consider scalability when structuring complex filters


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hockeystack.com/marketing-intelligence/using-the-new-dashboard-filters/when-to-use-and-vs.-or-logic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
