The problem I’m having
I’m trying to set up three similar macros, setting the same variable in all three. I keep getting a compilation error when trying to build or compile my models. I even get a compilation error when I try to build models that are upstream of the model where the new macros are being leveraged.
I think it might be an issue with how I’ve set up my variable but I haven’t been able to figure it out. Any help would be greatly appreciated!
The context of why I’m trying to do this
What I’ve already tried
I’ve tried adding double quotes around "extract(‘year’, " and ") - " and have tried taking the double curlies around 'effective_fiscal_year_number in the variable itself without any luck
Some example code or error messages
Sample macro:
{% macro is_qtd(effective_fiscal_year_number, effective_date) -%}
{% set fiscal_year_diff = extract('year', dbt_date.today()) - {{effective_fiscal_year_number}} %}
case
when dateadd('year', {{fiscal_year_diff}}, {{ effective_date }}) < dbt_date.today() and
quarter(dateadd('year', {{fiscal_year_diff}}, {{ effective_date }})) = quarter(dateadd('day', -1, dbt_date.today()))
else 0
end
{%- endmacro %}
Current error message:
Compilation Error
expected token ':', got '}'
line 2
{% set fiscal_year_diff = extract('year', dbt_date.today()) - {{effective_fiscal_year_number}} %}