---
title: Advanced Filtering
description: Filter your data to narrow the scope of metrics returned.
breadcrumbs: Docs > Metrics > Advanced Filtering
---

# Advanced Filtering

## Overview{% #overview %}

When using the Metrics Explorer, monitors, or dashboards to query metrics data, you can filter the data to narrow the scope of the timeseries returned. Any metric can be filtered by tag(s) using the **from** field to the right of the metric.

You can also perform advanced filtering with Boolean or Wildcard tag value filters. For queries outside of metrics data such as logs, traces, Network Monitoring, Real User Monitoring, Synthetics, or Security, see the [Log Search Syntax](https://docs.datadoghq.com/logs/explorer/search_syntax/) documentation for configuration.

## Boolean filtered queries{% #boolean-filtered-queries %}

The following syntax is supported for Boolean filtered metric queries:

- `!`
- `,`
- `NOT`, `not`
- `AND`, `and`
- `OR`, `or`
- `IN`, `in`
- `NOT IN`, `not in`

When including or excluding multiple tags:

- Include uses `AND` logic
- Exclude uses `OR` logic

For more information on tags, see the [Getting Started With Using Tags](https://docs.datadoghq.com/getting_started/tagging/using_tags/) guide.

**Note:** Symbolic boolean syntax (`!`, `,`) cannot be used with functional syntax operators (`NOT`, `AND`, `OR`, `IN`, `NOT IN`). The following query is considered *invalid*: `avg:mymetric{env:prod AND !region:us-east}`

### Boolean filtered query examples{% #boolean-filtered-query-examples %}

To use the examples below, click the code icon `</>` to see the query editor in the UI, and then copy and paste the query example into the query editor.

```
avg:system.cpu.user{env:staging AND (availability-zone:us-east-1a OR availability-zone:us-east-1c)} by {availability-zone}
```

{% video
   url="https://docs.dd-static.net/images/metrics/advanced-filtering/graph_editor_code_option.mp4" /%}

```
avg:system.cpu.user{env:shop.ist AND availability-zone IN (us-east-1a, us-east-1b, us-east4-b)} by {availability-zone}
```

{% image
   source="https://docs.dd-static.net/images/metrics/advanced-filtering/boolean_and_in.4ffaf8fa1a12dc6ce84b64a5673e7187.png?auto=format"
   alt="Boolean example AND IN" /%}

```
avg:system.cpu.user{env:prod AND location NOT IN (atlanta,seattle,las-vegas)}
```

{% image
   source="https://docs.dd-static.net/images/metrics/advanced-filtering/boolean_not_in.4188e6532f99d471cc236e230214528a.png?auto=format"
   alt="Boolean example NOT IN" /%}

## Wildcard filtered queries{% #wildcard-filtered-queries %}

Prefix, suffix, and substring wildcard tag filtering are supported:

- `pod_name: web-*`
- `cluster:*-trace`
- `node:*-prod-*`

### Wildcard filtered query examples{% #wildcard-filtered-query-examples %}

```
avg:system.disk.in_use{!device:/dev/loop*} by {device}
```

{% image
   source="https://docs.dd-static.net/images/metrics/advanced-filtering/wildcard_suffix_example.18f7a5b5b262632d1d7c884fcde7ec3b.png?auto=format"
   alt="Wildcard used as suffix" /%}

```
sum:kubernetes.pods.running{service:*-canary} by {service}
```

{% image
   source="https://docs.dd-static.net/images/metrics/advanced-filtering/wildcard_prefix_example.c80b88ab29c5f96ef743f1ae70586610.png?auto=format"
   alt="Wildcard used as prefix" /%}

```
avg:system.disk.utilized{region:*east*} by {region}
```

{% image
   source="https://docs.dd-static.net/images/metrics/advanced-filtering/wildcard_infix.609f406f4c5a9c48fc54fecc69616a22.png?auto=format"
   alt="Wildcard used as infix" /%}

## Exclusion functions{% #exclusion-functions %}

Add an [exclusion function](https://docs.datadoghq.com/dashboards/functions/exclusion/) to your query to:

- Exclude N/A values.
- Apply a minimum or maximum value to metrics that meet the threshold.
- Exclude values that are above or below threshold values.

Functions do not delete datapoints from Datadog, but they do remove datapoints from your visualizations.

## Further Reading{% #further-reading %}

- [Getting Started with Search in Datadog](https://docs.datadoghq.com/getting_started/search/)
- [Metrics Explorer](https://docs.datadoghq.com/metrics/explorer/)
- [Metrics Summary](https://docs.datadoghq.com/metrics/summary/)
- [Metrics Distributions](https://docs.datadoghq.com/metrics/distributions/)
- [Logs Query Filter and Search Syntax](https://docs.datadoghq.com/logs/explorer/search_syntax/)
- [Exclusion Functions](https://docs.datadoghq.com/dashboards/functions/exclusion/)
