---
schema_version: "1"
id: 70130b50f87d16c323d1ad178b372cb1740987b84421c808b46682c99a3f21d2
title: Filtering
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/semantic-layer/guides/metric-query-api-in-depth-filtering.md
canonical_url: https://developer.salesforce.com/docs/data/semantic-layer/guide/metric-query-api-in-depth-filtering.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 260bf22ec6e6e9a2ce04230aa8ab3c52f0e5f05745216b55e09b9a571b3b3d21
products:
  - Tableau Semantics Layer APIs
  - Data 360 Developer Documentation
---
# Filtering

Filters in Semantic Metric Queries allow you to refine your metric results by applying conditions to the data. While metric queries are primarily focused on predefined metrics, you can still apply filters to the underlying data to get more targeted results.

- The following example shows how to filter the time range of the metric:

```json
{
  "structuredMetricQuery": {
    "time_range": {
      "fieldName": "SemanticAccount_SDO.CreatedDate",
      "operator": "Between",
      "value": "2023-06-01 | 2023-06-30"
    },
    "submetric_definition": {
      "metric_api_name": "AnnualRevenueAmountPerName_md"
    },
    "model_api_name": "AccountSDM",
    "semantic_context": { // context
    }
  },
  "semanticModelId": "2SMxx0000004CAeGAM"
}
```

> **Performance:** Use `Between` for a range instead of separate `GreaterThanOrEqual` and `LessThanOrEqual` conditions; a single range predicate lets the engine prune partitions on date and numeric columns.

- The following example shows how to apply a metric-level filter in a metric query:

```json
{
  "structuredMetricQuery": {
    "submetric_definition": {
      "metric_api_name": "AnnualRevenueAmountPerName_md",
      "filters": [
        {
          "fieldName": "SemanticAccount_SDO.Name",
          "operator": "Equals",
          "value": "MyName"
        }
      ]
    },
    "model_api_name": "AccountSDM",
    "semantic_context": { // context
    }
  },
  "semanticModelId": "2SMxx0000004CAeGAM"
}
```

- The following example shows how to apply filters to additional dimensions in a metric query:

```json
{
  "structuredMetricQuery": {
    "filters": [
      {
        "fieldName": "SemanticAccount_SDO.CreatedDate",
        "operator": "GreaterThanOrEqualTo",
        "value": "2024-01-01"
      }
    ],
    "submetric_definition": {
      "metric_api_name": "AnnualRevenueAmountPerName_md"
    },
    "model_api_name": "AccountSDM",
    "semantic_context": { // context
    }
  },
  "semanticModelId": "2SMxx0000004CAeGAM"
}
```
