> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.prolific.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.prolific.com/_mcp/server.

# Advanced filtering

# Advanced filtering with AND/OR logic

With more advanced filtering features, you can express audience logic that cannot be represented by a flat list of filters.

Use these when you need to target participants who match one of several valid paths, such as:

* participants resident in one of several countries
* participants in a participant group who fall within a target age range
* participants who took a previous study and passed a screener, or participants who have not taken that study yet

## How filter logic is evaluated

A study or filter set can contain leaf filters and composite groups.

Leaf filters are the standard select and range filters. See [Filters Overview](/api-reference/filters/filters-overview) for examples of each.

Composite groups use `filter_id: "and"` or `filter_id: "or"` and put their child filters in `selected_filters`.

* `and`: every child filter in the group must match.
* `or`: at least one child filter in the group must match.
* A flat list of top-level filters is treated as an implicit `and`.

## Flat OR within one attribute

For a select filter, multiple `selected_values` means "match any of these selected values". The values are the choice IDs returned for that filter by the [filters list endpoint](/api-reference/filters/get-filters).

For example, this selects participants resident in either of two countries:

```json
{
  "filter_id": "current-country-of-residence",
  "selected_values": ["0", "1"]
}
```

You can use this form to simplify the query when the OR choices all belong to the same filter attribute.

## OR across different filters

To match participants who satisfy one of several different filters, you can wrap the leaf filters in an `or` group.

For example, this matches participants who are either in the participant group or aged between 18 and 30:

```json
{
  "filter_id": "or",
  "selected_filters": [
    {
      "filter_id": "participant_group_allowlist",
      "selected_values": ["<participant_group_id>"]
    },
    {
      "filter_id": "age",
      "selected_range": {
        "lower": 18,
        "upper": 30
      }
    }
  ]
}
```

## Nested AND/OR groups

You can use nested composite groups when each OR branch has its own AND requirements.

For example, this matches participants who are either:

* in the participant group and aged between 18 and 30
* in the previous study allowlist and have an approval rate of at least 95

```json
{
  "filter_id": "or",
  "selected_filters": [
    {
      "filter_id": "and",
      "selected_filters": [
        {
          "filter_id": "participant_group_allowlist",
          "selected_values": ["<participant_group_id>"]
        },
        {
          "filter_id": "age",
          "selected_range": {
            "lower": 18,
            "upper": 30
          }
        }
      ]
    },
    {
      "filter_id": "and",
      "selected_filters": [
        {
          "filter_id": "previous_studies_allowlist",
          "selected_values": ["<previous_study_id>"]
        },
        {
          "filter_id": "approval_rate",
          "selected_range": {
            "lower": 95
          }
        }
      ]
    }
  ]
}
```

## Saved filter sets

Compound `and` / `or` groups like the examples above can be saved as a filter set and reused across studies. See [Filter Sets](/api-reference/filter-sets) for how to create, version, and apply them.

## Limitations

Compound `and` / `or` filter groups are not currently supported for Quota or Representative Sample study types.