metrics - semantic model model missing

I modified the metrics,yml config file to the latest standards. Example snippet from the file,

  • name: total_sales
    description: “The total value of sales”
    type: simple
    label: “Total Sales”
    type_params:
    measure:
    name: sales_price
    filter: |
    is_valid_sale = true AND
    meta_project_status IN (‘Active’, ‘Completed’) AND
    product_line != ‘Customer Service’ AND
    project_type != ‘Ring Sizer’ AND
    sale_type != ‘Redo’

But I am getting this error, Parsing Error in metric total_sales (models/1-staging/aggregates/metrics.yml)

A semantic model having a measuresales_price does not exist but was referenced.

I am not sure how to fix this as I am relatively to trying this. Please help me. Urgent business problem

Hi @sreenig!

This error is basically saying that “sales_price” is not defined in your semantic models.

  • Have you changed/updated those?
  • Could there be a misspelling like “sale_price” or “sales_prices” instead of “sales_price”?
  • Are there any other errors in the complete DAG execution or is this the only one?

You could revert the changes in your dev environment and start changing things one at a time to detect at which step the error occurs.

Hi Marcelo,

Yes, I updated them. They used to be like this. But I got error for dimensions and timestamp(

  • &sales_metric # define alias anchor

    name: total_sales

    label: Total Sales

    model: ref(‘prod_orders_and_projects’)

    description: “The total value of sales”

    expression: sales_price

    calculation_method: sum

    filters:

    - field: is_valid_sale

    operator: ‘is’

    value: ‘true’

    - field: meta_project_status

    operator: ‘in’

    value: ‘(“Active”,“Completed”)’

    - field: product_line

    operator: ‘!=’

    value: ‘“Customer Service”’

    - field: project_type

    operator: ‘!=’

    value: ‘“Ring Sizer”’

    - field: sale_type

    operator: ‘!=’

    value: ‘“Redo”’

    timestamp: date_started

    time_grains: [day, week, month, quarter, year]

    type: sum

    sql: sales_price

    timestamp: date_started

    filters:

    - field: is_valid_sale

    operator: “=”

    value: true

    - field: meta_project_status

    operator: “in”

    value: [“Active”, “Completed”]

    - field: product_line

    operator: “!=”

    value: “Customer Service”

    - field: project_type

    operator: “!=”

    value: “Ring Sizer”

    - field: sale_type

    operator: “!=”

    value: “Redo”

I changed to the above in the question. Please let me know how I should go about it?

Could you please check your semantic model yaml file where the measure sales_price is defined? (Paste partial screenshot or code block please)

I am not able to find that file. This is mentioned in metrics.yml file. Are those the same? I am a bit new to dbt. Please help me out here. I am trying to fix something which I didnt even setup.


I tried creating the semantics model. But I still get this error

Parsing Error in metric total_sales (models/1-staging/aggregates/metrics.yml)
*** A semantic model having a measure sales_price does not exist but was refer***enced.

Metrics can be defined in the same YAML files as your semantic models, or split into separate YAML files into any other subdirectories (provided that these subdirectories are also within the same dbt project repo).

In that article you have an example how the measure (sales_price) should appear.

Almost nothing in dbt can be done by “tinkering to see if it works”, but the semantic layer even less so, because it’s precisely where the metrics that everyone trusts come from. It may run without errors but not give the result they’re looking for.

Could you please explain this? Does that mean the results need not be accurate or wont be accurate? If former, I just need to have a semantic layer?

I created a time_spine.sql under utility folder. I even configured in my dbt_project.yml and created a semantic layer time_spine.yml.

This is the code I wrote for the time_spine.sql

WITH date_spine AS (
SELECT
CAST(‘2020-01-01’ AS DATE) AS date_day – Replace with your desired start date
UNION ALL
SELECT
DATE_ADD(date_day, INTERVAL 1 DAY)
FROM
date_spine
WHERE
date_day < CAST(CURRENT_DATE AS DATE) – Replace with your desired end date
)

SELECT
date_day
FROM
date_spine
ORDER BY
date_day

still getting the error like this

Parsing Error
** The semantic layer requires a time spine model with granularity DAY or smaller in the project, but none was found. Guidance on creating this model can be found on our docs site (MetricFlow time spine | dbt Developer Hub).**