> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gp.scale.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Metric Widget

> Display single aggregation values like averages, counts, and percentiles

<Info>
  **Using Sample Data**: The examples on this page use fields from our <a href="/assets/sample-data/sample-evaluation.csv" download>sample dataset</a>. Download it and create an evaluation with it to follow along with this tutorial.
</Info>

<Frame>
  <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-base-result.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=ee9eaf3c085b1f481ff6607e639f404b" alt="Metric Widget Example" width="612" height="214" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-base-result.png" />
</Frame>

## When to Use

Use metric widgets to:

* Display top-level aggregation values (e.g., "Average Model Score: 0.87")
* Show summary statistics (e.g., "Total Items: 1,247")
* Highlight key thresholds (e.g., "95th Percentile Latency: 234ms")
* Create metric cards for at-a-glance monitoring
* Track pass rates and percentages

## Configuration

### Required Fields

<ParamField body="title" type="string" required>
  Widget display name shown on the dashboard
</ParamField>

<ParamField body="type" type="string" required>
  Must be set to "metric"
</ParamField>

<ParamField body="query" type="object" required>
  MetricQuery with exactly one aggregation function
</ParamField>

### Query Requirements

Metric widgets require a **MetricQuery** with these constraints:

* Must have exactly one item in the `select` clause
* That item must be an `AGGREGATION` expression (not a raw column)
* Can optionally include `filter` conditions
* Cannot use `groupBy`, `orderBy`, or `limit`

## Creating in the UI

<Steps>
  <Step title="Open Widget Creator">
    From your dashboard, click "Add Widget" and select "Query Value"
  </Step>

  <Step title="Enter Title">
    Give your metric a descriptive name (e.g., "Average Score")
  </Step>

  <Step title="Configure Query">
    <Frame>
      <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-base-form.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=d1f4df63b9490038c57d2d2f8ee301f6" alt="Metric Query Builder" width="2586" height="1578" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-base-form.png" />
    </Frame>

    * **Column**: Select the field to aggregate
    * **Aggregation**: Choose the function
    * **Filter** (optional): Add conditions to narrow the data
  </Step>

  <Step title="Create Widget">
    Click "Add" to compute and display the result

    <Frame>
      <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-base-result.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=ee9eaf3c085b1f481ff6607e639f404b" alt="Created Metric Widget" width="612" height="214" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-base-result.png" />
    </Frame>
  </Step>
</Steps>

## Output Format

Metric widgets return a single scalar value:

```json theme={null}
{
  "type": "metric",
  "data": 0.873
}
```

The `data` field contains the computed number, which can be:

* A decimal number (0.873)
* An integer (1247)
* A percentage (0.85 representing 85%)

## Example Use Cases

### Use Case 1: Average Overall Score

Display the mean overall score across all evaluation items.

<Frame>
  <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-average-score.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=3665785add22025b82e7ddf0b27a3089" alt="Average Overall Score Metric" width="2484" height="1578" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-average-score.png" />
</Frame>

<CodeGroup>
  ```python Python theme={null}
  widget = client.evaluation_dashboards.widgets.create(
      dashboard_id=dashboard.id,
      title="Average Overall Score",
      type="metric",
      query={
          "select": [
              {
                  "expression": {
                      "type": "AGGREGATION",
                      "function": "AVG",
                      "column": "overall_score",
                      "source": "data"
                  }
              }
          ]
      }
  )
  ```

  ```json JSON theme={null}
  {
    "title": "Average Overall Score",
    "type": "metric",
    "query": {
      "select": [
        {
          "expression": {
            "type": "AGGREGATION",
            "function": "AVG",
            "column": "overall_score",
            "source": "data"
          }
        }
      ]
    }
  }
  ```
</CodeGroup>

***

### Use Case 2: Total Evaluation Count

Show how many evaluation items are in the dataset.

<Frame>
  <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-total-evaluations.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=273cb5852f56e52d26f0d15490121566" alt="Total Evaluations Metric" width="2484" height="1578" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-total-evaluations.png" />
</Frame>

<CodeGroup>
  ```python Python theme={null}
  widget = client.evaluation_dashboards.widgets.create(
      dashboard_id=dashboard.id,
      title="Total Evaluations",
      type="metric",
      query={
          "select": [
              {
                  "expression": {
                      "type": "AGGREGATION",
                      "function": "COUNT",
                      "column": "*"
                  }
              }
          ]
      }
  )
  ```

  ```json JSON theme={null}
  {
    "title": "Total Evaluations",
    "type": "metric",
    "query": {
      "select": [
        {
          "expression": {
            "type": "AGGREGATION",
            "function": "COUNT",
            "column": "*"
          }
        }
      ]
    }
  }
  ```
</CodeGroup>

***

### Use Case 3: High Performance Rate

Calculate percentage of evaluations scoring 85 or above.

<Frame>
  <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-high-performance-rate.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=b7a507f9572e1c0ebde3eace2db35679" alt="High Performance Rate Metric" width="2484" height="1578" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-high-performance-rate.png" />
</Frame>

<CodeGroup>
  ```python Python theme={null}
  widget = client.evaluation_dashboards.widgets.create(
      dashboard_id=dashboard.id,
      title="High Performance Rate",
      type="metric",
      query={
          "select": [
              {
                  "expression": {
                      "type": "AGGREGATION",
                      "function": "PERCENTAGE",
                      "column": "overall_score",
                      "params": {
                          "percentage_filters": {
                              "conditions": [
                                  {
                                      "column": "overall_score",
                                      "source": "data",
                                      "operator": ">=",
                                      "value": 85
                                  }
                              ]
                          }
                      }
                  }
              }
          ]
      }
  )
  ```

  ```json JSON theme={null}
  {
    "title": "High Performance Rate",
    "type": "metric",
    "query": {
      "select": [
        {
          "expression": {
            "type": "AGGREGATION",
            "function": "PERCENTAGE",
            "column": "overall_score",
            "params": {
              "percentage_filters": {
                "conditions": [
                  {
                    "column": "overall_score",
                    "source": "data",
                    "operator": ">=",
                    "value": 85
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
  ```
</CodeGroup>

***

### Use Case 4: 95th Percentile Overall Score

Show the 95th percentile to understand top-end performance.

<Frame>
  <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-p95-overall-score.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=980c7810f239e893a7e5279c022d84c3" alt="95th Percentile Overall Score Metric" width="2484" height="1578" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-p95-overall-score.png" />
</Frame>

<CodeGroup>
  ```python Python theme={null}
  widget = client.evaluation_dashboards.widgets.create(
      dashboard_id=dashboard.id,
      title="95th Percentile Overall Score",
      type="metric",
      query={
          "select": [
              {
                  "expression": {
                      "type": "AGGREGATION",
                      "function": "PERCENTILE",
                      "column": "overall_score",
                      "source": "data",
                      "params": {
                          "percentile": 95
                      }
                  }
              }
          ]
      }
  )
  ```

  ```json JSON theme={null}
  {
    "title": "95th Percentile Overall Score",
    "type": "metric",
    "query": {
      "select": [
        {
          "expression": {
            "type": "AGGREGATION",
            "function": "PERCENTILE",
            "column": "overall_score",
            "source": "data",
            "params": {
              "percentile": 95
            }
          }
        }
      ]
    }
  }
  ```
</CodeGroup>

***

### Use Case 5: Average Score for Technical Tasks

Calculate average score for only technical task types.

<Frame>
  <img src="https://mintcdn.com/scalegp/3SJ3nurBJCdCWISt/images/v5/evaluation-dashboards/widget-types/metric/metric-technical-tasks-avg-score.png?fit=max&auto=format&n=3SJ3nurBJCdCWISt&q=85&s=0150722f90849aa377bfcfa33107f602" alt="Technical Tasks Avg Score Metric" width="2484" height="1578" data-path="images/v5/evaluation-dashboards/widget-types/metric/metric-technical-tasks-avg-score.png" />
</Frame>

<CodeGroup>
  ```python Python theme={null}
  widget = client.evaluation_dashboards.widgets.create(
      dashboard_id=dashboard.id,
      title="Technical Tasks Avg Score",
      type="metric",
      query={
          "select": [
              {
                  "expression": {
                      "type": "AGGREGATION",
                      "function": "AVG",
                      "column": "overall_score",
                      "source": "data"
                  }
              }
          ],
          "filter": {
              "conditions": [
                  {
                      "column": "prompt_category",
                      "source": "data",
                      "operator": "=",
                      "value": "technical"
                  }
              ]
          }
      }
  )
  ```

  ```json JSON theme={null}
  {
    "title": "Technical Tasks Avg Score",
    "type": "metric",
    "query": {
      "select": [
        {
          "expression": {
            "type": "AGGREGATION",
            "function": "AVG",
            "column": "overall_score",
            "source": "data"
          }
        }
      ],
      "filter": {
        "conditions": [
          {
            "column": "prompt_category",
            "source": "data",
            "operator": "=",
            "value": "technical"
          }
        ]
      }
    }
  }
  ```
</CodeGroup>

## Related Documentation

* [Query Language Reference](../query-language) - Full query syntax guide
* [All Widget Types](./overview) - Compare different widget types
* [Table Widget](./table) - For multi-row displays
* [API Reference](/reference/v5/evaluation-dashboards) - Explore programmatic widget creation
