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:
Semantic Metric Query with time range filter
1{
2  "structuredMetricQuery": {
3    "time_range": {
4      "fieldName": "SemanticAccount_SDO.CreatedDate",
5      "operator": "Between",
6      "value": "2023-06-01 | 2023-06-30"
7    },
8    "submetric_definition": {
9      "metric_api_name": "AnnualRevenueAmountPerName_md"
10    },
11    "model_api_name": "AccountSDM",
12    "semantic_context": { // context
13    }
14  },
15  "semanticModelId": "2SMxx0000004CAeGAM"
16}
  • The following example shows how to apply a metric-level filter in a metric query:
Semantic Metric Query with metric level filter
1{
2  "structuredMetricQuery": {
3    "submetric_definition": {
4      "metric_api_name": "AnnualRevenueAmountPerName_md",
5      "filters": [
6        {
7          "fieldName": "SemanticAccount_SDO.Name",
8          "operator": "Equals",
9          "value": "MyName"
10        }
11      ]
12    },
13    "model_api_name": "AccountSDM",
14    "semantic_context": { // context
15    }
16  },
17  "semanticModelId": "2SMxx0000004CAeGAM"
18}
  • The following example shows how to apply filters to additional dimensions in a metric query:
Semantic Metric Query with dimension filter
1{
2  "structuredMetricQuery": {
3    "filters": [
4      {
5        "fieldName": "SemanticAccount_SDO.CreatedDate",
6        "operator": "GreaterThanOrEqual",
7        "value": "2024-01-01"
8      }
9    ],
10    "submetric_definition": {
11      "metric_api_name": "AnnualRevenueAmountPerName_md"
12    },
13    "model_api_name": "AccountSDM",
14    "semantic_context": { // context
15    }
16  },
17  "semanticModelId": "2SMxx0000004CAeGAM"
18}