Is there a way to define a variable in the dbt_pro...
# community-support
m
Is there a way to define a variable in the dbt_project.yml and I want to use these variables in the same yml file. I have tried but it can not compile the
var('channel_id_fin')
. I am able to use it in .sql files with the same syntax but not in the yml files.
m
I have never managed to do so, I was told it was not possible, so I started putting default values like this to make it compile :
{{var('businessUnitIdentifier', '015')}}
but when running a dbt command, it will take the right value, but it still needs a default one to work
m
how the logic you have works? can you please explain little bit?
m
of course here is a sample of my dbt_project.yml :
models:
internalDataProcessing:
+database: "{{ target.project }}"
+persist_docs:
relation: true
columns: true
local:
+enabled: "{{var('businessUnitIdentifier', '005') != '015'}}"
+materialized: table
staging:
+schema: "ds_internalDataProcessing"
materialized: table
intermediate:
+schema: "dl_internalDataProcessing"
materialized: table
publish:
+schema: "internalDataProcessing"
materialized: table
global:
+enabled: "{{var('businessUnitIdentifier', '015') == '015'}}"
+schema: "internalDataProcessing"
materialized: table
vars:
"businessUnitIdentifier": "003"
My goal here was to execute models of folder "local" only if my businessUnitIdentifier was not equal to 015, and execute "global" folder only in 015 case. My issue is that writing
{{var('businessUnitIdentifier')}}
in the dbt_project.yml got me an error that it did not know the value of businessUnitIdentifier. So I put the default value "015" so it does not bring me issue. But that still did not bother me to run my models and get the right default var "003" (and when wanting 015, I ran
dbt run --vars '{"businessUnitIdentifier":"015"}'
to execute only the global folder) Hope my use case is clear enough for you !