# Predicted By Check Examples

Source: https://userguide.qualytics.io/data-quality-checks/predicted-by/deep-dive/examples/

Three real-world scenarios that show how the Predicted By check is typically used in production: validating a derived discount, reconciling a forecast against actuals, and auditing a metric that should track another one. The first two run at 100% coverage and report Record Anomalies; the third lowers coverage and reports a Shape Anomaly instead.

**Tab: A Derived Discount**

**The situation:** Line discounts are generated as 8% of the extended price, with small rounding differences from the pricing service. A discount more than 2 away from that figure means the rate was applied to the wrong base or overridden by hand, and the invoice total will be wrong.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Predicted By |
| Field | `l_discount` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Expression | `l_extendedprice * 0.08` |
| Tolerance | `2` |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Pricing Engineering)* |
| Description | The discount must stay within 2 of 8% of the extended price. |
| Tags | `business-logic`, `pricing` |
| Additional Metadata | `jira: DATA-10800` |
| Status | Active |

**Payload**

```json
{
    "description": "The discount must stay within 2 of 8% of the extended price.",
    "rule": "predictedBy",
    "fields": ["l_discount"],
    "container_id": 145,
    "coverage": 1,
    "filter": null,
    "properties": {
        "expression": "l_extendedprice * 0.08",
        "tolerance": 2
    },
    "tags": ["business-logic", "pricing"],
    "additional_metadata": {"jira": "DATA-10800"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 12
}
```

**Sample Data**

| l_orderkey | l_extendedprice | l_discount |
| --- | --- | --- |
| 1 | 100 | 8 |
| 2 | 100 | 12 |
| 3 | 100 | 9 |
| 4 | 100 | 3 |

**What gets flagged**

The prediction for every row here is 8. Line 3 sits one away and passes, inside the band of 2. Line 2 is four above and line 4 is five below, both outside it. The band is symmetric, so a discount that is too small fails exactly like one that is too large. Coverage is 100%, so each failing row is reported as its own Record Anomaly.

> **Example: Record Anomaly**
>
> l_discount has the value 12, which falls outside its predicted range. The prediction allows a tolerance of 2 around the expression: l_extendedprice * 0.08

**Flowchart**

```mermaid
graph TD
    A["Read the row"] --> B["Evaluate l_extendedprice * 0.08"]
    B --> C{"Is the difference from<br/>l_discount at most 2?"}
    C -->|Yes| D["Row passes"]
    B -->|Returns NULL| D
    C -->|No| E["Flag row and quote the<br/>expression and tolerance"]
```

**Equivalent SQL**

```sql
-- Rows the Predicted By check would flag.
SELECT l.*
FROM lineitem l
WHERE abs((l.l_extendedprice * 0.08) - l.l_discount) > 2;
```

**Tab: Forecast Against Actuals**

**The situation:** A demand planning table stores both the forecast units and the units actually shipped for each product and week. The planning team accepts a gap of up to 50 units; beyond that the forecast model needs review. Weeks that have not closed yet are excluded, because their actuals are still accumulating.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Predicted By |
| Field | `actual_units` |
| Filter | `week_status = 'closed'` |
| Custom Anomaly Description | Off |
| Expression | `forecast_units` |
| Tolerance | `50` |
| Coverage | 100% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Demand Planning)* |
| Description | Actual units must land within 50 of the forecast for a closed week. |
| Tags | `forecasting`, `planning` |
| Additional Metadata | `jira: DATA-10822` |
| Status | Active |

**Payload**

```json
{
    "description": "Actual units must land within 50 of the forecast for a closed week.",
    "rule": "predictedBy",
    "fields": ["actual_units"],
    "container_id": 512,
    "coverage": 1,
    "filter": "week_status = 'closed'",
    "properties": {
        "expression": "forecast_units",
        "tolerance": 50
    },
    "tags": ["forecasting", "planning"],
    "additional_metadata": {"jira": "DATA-10822"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 47
}
```

**Sample Data** (filtered to `week_status = 'closed'`)

| product | week | forecast_units | actual_units |
| --- | --- | --- | --- |
| P-100 | 2026-W08 | 1,200 | 1,235 |
| P-101 | 2026-W08 | 800 | 1,410 |
| P-102 | 2026-W08 | 450 | 430 |

**Why the filter matters**

The filter runs **before** the comparison, so weeks that are still accumulating actuals are never evaluated. Without it, every open week would look like a forecast miss simply because the week is not over.

**What gets flagged**

`P-101` shipped 610 units above forecast, far outside the 50-unit band, so the model under-predicted that product badly. The other two land within 35 and 20 of their forecasts and pass. Coverage is 100%, so the failure is reported as a Record Anomaly, and the message names the filter that scoped the evaluation.

> **Example: Record Anomaly**
>
> actual_units has the value 1410, which falls outside its predicted range (applied to records where week_status = 'closed'). The prediction allows a tolerance of 50 around the expression: forecast_units

**Flowchart**

```mermaid
graph TD
    A["Apply filter: week_status = 'closed'"] --> B["Evaluate forecast_units"]
    B --> C{"Is the difference from<br/>actual_units at most 50?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E["Flag row.<br/>Message names the filter:<br/>applied to records where week_status = 'closed'"]
```

**Equivalent SQL**

```sql
-- Rows the check would flag.
SELECT d.*
FROM demand_plan d
WHERE d.week_status = 'closed'
  AND NOT (abs(d.forecast_units - d.actual_units) <= 50);
```

**Tab: A Metric That Should Track Another**

**The situation:** A reporting table stores a daily revenue figure alongside the sum the transactional system reported. The two are computed by different pipelines and should agree within 100 currency units. A migration is rewriting part of the history, so a small share is expected to disagree while it runs, and coverage is lowered to 95%.

**Check configuration**

| Field | Value |
| --- | --- |
| Rule | Predicted By |
| Field | `reported_revenue` |
| Filter | *(none)* |
| Custom Anomaly Description | Off |
| Expression | `source_revenue` |
| Tolerance | `100` |
| Coverage | 95% |
| Owner | *(check creator)* |
| Anomaly Assignee | *(Reporting Data team)* |
| Description | Reported revenue must track the source figure within 100. |
| Tags | `reconciliation`, `migration` |
| Additional Metadata | `jira: DATA-10841` |
| Status | Active |

**Payload**

```json
{
    "description": "Reported revenue must track the source figure within 100.",
    "rule": "predictedBy",
    "fields": ["reported_revenue"],
    "container_id": 733,
    "coverage": 0.95,
    "filter": null,
    "properties": {
        "expression": "source_revenue",
        "tolerance": 100
    },
    "tags": ["reconciliation", "migration"],
    "additional_metadata": {"jira": "DATA-10841"},
    "anomaly_message_field": null,
    "template_id": null,
    "status": "Active",
    "owner_id": 7,
    "default_anomaly_assignee_id": 41
}
```

**Sample Data**

| report_date | source_revenue | reported_revenue |
| --- | --- | --- |
| 2026-03-08 | 48,200 | 48,255 |
| 2026-03-09 | 51,400 | 44,900 |
| 2026-03-10 | 49,750 | 61,300 |
| 2026-03-11 | 50,100 | 50,060 |

**What gets flagged**

The 9th and 10th are thousands away from the source figure, well outside the 100-unit band: the migration reprocessed those two days with an incomplete set of transactions. The other two agree within 55 and 40. Only 50% of the rows pass, below the 95% coverage threshold, so the check reports a single Shape Anomaly for the dataset with a sample of the offending rows. Coverage below 100% does not produce Record Anomalies.

> **Example: Shape Anomaly**
>
> reported_revenue values fall outside their predicted range, affecting 2 of 4 asserted records. The prediction allows a tolerance of 100 around the expression: source_revenue

**Flowchart**

```mermaid
graph TD
    A["Read the row"] --> B["Evaluate source_revenue"]
    B --> C{"Is the difference from<br/>reported_revenue at most 100?"}
    C -->|Yes| D["Row passes"]
    C -->|No| E["Count the row as failing"]
    D --> F{"Passing fraction<br/>at or above 95%?"}
    E --> F
    F -->|Yes| G["Check passes"]
    F -->|No| H["Shape Anomaly for the dataset"]
```

**Equivalent SQL**

```sql
-- Rows the check would flag.
SELECT r.*
FROM revenue_report r
WHERE NOT (abs(r.source_revenue - r.reported_revenue) <= 100);
```

## See Also

- **Best Practices**

  Guidelines for writing the prediction, sizing the tolerance, and choosing between this rule and a simpler one.

  [Best Practices](https://userguide.qualytics.io/data-quality-checks/predicted-by/deep-dive/best-practices/)
- **Permissions**

  The team permission each action needs: view, create, edit, archive, restore, and delete.

  [Permissions](https://userguide.qualytics.io/data-quality-checks/predicted-by/deep-dive/permissions/)
- **How It Works**

  The complete reference: definition, field scope, the prediction expression, how the tolerance band works, date and time targets, NULL handling, filter behavior, and coverage.

  [How It Works](https://userguide.qualytics.io/data-quality-checks/predicted-by/deep-dive/how-it-works/)
- **Anomaly Reporting**

  The anomaly messages the check produces, what the numbers mean, Source Records behavior, and Custom Anomaly Description.

  [Anomaly Reporting](https://userguide.qualytics.io/data-quality-checks/predicted-by/deep-dive/anomaly-reporting/)

*Last updated: October 19, 2026.*
