High severitycompilation
Power BI Refresh Error:
DbtVariableUndefinedError
What does this error mean?
A dbt model or macro references a variable with var('name') that was not defined in dbt_project.yml or passed on the command line, causing the run to fail with an undefined variable error.
Common causes
- 1The variable is referenced in a model but is missing from the vars block in dbt_project.yml
- 2The variable was passed with --vars on the command line locally but not set in the dbt Cloud job definition
- 3The variable name contains a typo or uses a different casing than defined
- 4A package macro uses a variable that requires a project-level definition not included in the project
How to fix it
- 1Step 1: Add the variable with a default value in dbt_project.yml: vars: my_variable: 'default_value'.
- 2Step 2: Use var('my_variable', 'fallback') in models and macros to provide a runtime fallback and avoid hard failures.
- 3Step 3: For dbt Cloud jobs, add the variable in the job configuration under Environment Variables or --vars in the command.
- 4Step 4: Search all models and macros for var(' calls to map all undefined variables and add them to dbt_project.yml.
- 5Step 5: Run dbt compile to verify all variables resolve before executing the pipeline.