dbt-labs / dbt-labs/dbt-semantic-interfaces
Metric cannot reference a measure defined in the same semantic model (metric references non-existent measure)
- Dominant language
- Python
- Stars
- 103
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
### Is this a new bug in dbt-semantic-interfaces?
- [x] I believe this is a new bug in dbt-semantic-interfaces
- [x] I have searched the existing issues, and I could not find an existing issue for this bug
### Current Behavior
When defining a ratio metric that references a measure declared in the same semantic model file, dbt raises the following parsing error:
The metric `total_calls` does not exist but was referenced by metric `calls_per_order`
This happens even though:
1. total_calls is correctly defined as a measure
2. the metric is declared in the same YAML file
3. there are no naming conflicts or typos
### Expected Behavior
dbt should successfully resolve total_calls as a valid measure when:
1. the metric and semantic model are declared in the same YAML file
2. the referenced measure exists under semantic_models.measures
If cross–semantic-model metrics are unsupported, the error message should instead explicitly state that metrics must only reference measures within the same semantic model, rather than indicating that the measure does not exist.
### Steps To Reproduce
1. Create a semantic model with a valid measure:
semantic_models:
- name: cpo_dashboard
model: ref('cpo_dashboard')
measures:
- name: total_calls
expr: calls
agg: sum
2. Define a ratio metric in the same YAML file:
metrics:
- name: calls_per_order
type: ratio
type_params:
numerator: total_calls
denominator: completed_orders
3. Run any dbt command that parses semantic models
4. Observe the parsing error indicating that total_calls does not exist.
### Relevant log output
```shell
05:07:20 Encountered an error:
Parsing Error in metric calls_per_order (models/semantics/support_communication/mart_snc_cpo_dashboard.yml)
The metric `total_calls` does not exist but was referenced by metric `calls_per_order`.
```
### Environment
```markdown
- OS: macOS (Darwin, ARM64)
- Python: 3.12.4
- dbt-core: 1.11.3
- dbt-snowflake: 1.11.1
- dbt-semantic-interfaces: 0.9.0
```
### Additional Context
version: 2
semantic_models:
- name: cpo_dashboard
model: ref('cpo_dashboard')
description: "Aggregated mart for CPO analysis. The grain is defined by the unique combination of Date, Geography, Vehicle, Vertical, Caller Persona, and Order Status."
defaults:
agg_time_dimension: call_date
config:
meta:
business_owner: "cp-da@theporter.in"
business_domain: "S&C Business Team"
technical_owner:
- "employee-1@theporter.in"
- "cp-da@theporter.in"
refresh_cadence: "daily"
tags:
- "CPO Dashboard and Support load metrics"
entities:
- name: cpo_dashboard_grain
type: primary
expr: "dated || '_' || geo_region_id || '_' || vehicle_id || '_' || caller_type || '_' || order_status || '_' || source"
dimensions:
- name: call_date
type: time
type_params:
time_granularity: day
expr: dated
- name: caller_persona
type: categorical
expr: caller_type
- name: call_tier
type: categorical
expr: call_type
- name: order_lifecycle_status
type: categorical
expr: order_status
- name: call_request_source
type: categorical
expr: source
- name: business_vertical
type: categorical
expr: vertical
measures:
- name: total_calls
description: "Sum of calls aggregated at the daily composite grain."
expr: calls
agg: sum
agg_time_dimension: call_date
metrics:
- name: calls_per_order
description: "Average number of calls made relative to completed orders. High-level efficiency metric for the S&C business."
type: ratio
type_params:
numerator: total_calls
denominator: completed_orders
label: "Calls Per Order (CPO)"
config:
meta:
ownership:
business_owner: "Core Platform - S&C"
technical_owner:
- "employee-1@theporter.in"
- "cp-da@theporter.in"
freshness:
refresh_cadence: "daily"
technical_details:
calculation_logic: "sum(total_calls) from cpo_dashboard / sum(completed_orders) from snc_orders"
source_semantic_model: [cpo_dashboard, snc_orders]
interpretation: "Lower is better. Indicates higher support efficiency."
relationship:
parent_metrics: IPO
child_metrics: TPO, CSAT, NPS
related_metrics: AHT
governance:
approved_by: da-manager@theporter.in
version: 1.0
Contributor guide
Assessment
This issue has not been assessed yet.