CurtisMiddleton
3 years agoQrew Trainee
JINJA If Statement Help
Hi,
I'm building a pipeline and am struggling with an if statement.
What I want it to do is look at the prior month and round up to the nearest quarter for that prior month. Ex: Today would round to 202303 whereas July 15, 2023 would round to 202306.
Here is what I have so far. I've troubleshooted my set variables and those function as expected. It's when I get to the if statement where it isn't happy:
{% set Reporting_MM = "{:%m}".format(time.now - time.delta(months=1)) %}
{% set Reporting_YYYY = "{:%Y}".format(time.now - time.delta(months=1)) %}
{% set MARCH = Reporting_YYYY ~ '03' %}
{% set JUNE = Reporting_YYYY ~ '06' %}
{% set SEPTEMBER = Reporting_YYYY ~ '09' %}
{% set DECEMBER= Reporting_YYYY ~ '12' %}
{% if Reporting_MM in [ '01', '02', '03'] %}
{{ MARCH }}
{% elif Reporting_MM in [ '04', '05', '06'] %}
{{ JUNE }}
{% elif Reporting_MM in [ '07', '08', '09'] %}
{{ SEPTEMBER }}
{% elif Reporting_MM in [ '10', '11', '12'] %}
{{ DECEMBER }}
{% else %}
{{ ERROR }}
{% endif %}
------------------------------
Curtis Middleton
------------------------------
I'm building a pipeline and am struggling with an if statement.
What I want it to do is look at the prior month and round up to the nearest quarter for that prior month. Ex: Today would round to 202303 whereas July 15, 2023 would round to 202306.
Here is what I have so far. I've troubleshooted my set variables and those function as expected. It's when I get to the if statement where it isn't happy:
{% set Reporting_MM = "{:%m}".format(time.now - time.delta(months=1)) %}
{% set Reporting_YYYY = "{:%Y}".format(time.now - time.delta(months=1)) %}
{% set MARCH = Reporting_YYYY ~ '03' %}
{% set JUNE = Reporting_YYYY ~ '06' %}
{% set SEPTEMBER = Reporting_YYYY ~ '09' %}
{% set DECEMBER= Reporting_YYYY ~ '12' %}
{% if Reporting_MM in [ '01', '02', '03'] %}
{{ MARCH }}
{% elif Reporting_MM in [ '04', '05', '06'] %}
{{ JUNE }}
{% elif Reporting_MM in [ '07', '08', '09'] %}
{{ SEPTEMBER }}
{% elif Reporting_MM in [ '10', '11', '12'] %}
{{ DECEMBER }}
{% else %}
{{ ERROR }}
{% endif %}
------------------------------
Curtis Middleton
------------------------------