dbt jinja conditional logic

Hi,

I’m a dbt new user and have the following problem:

I’m trying to create a custom test which compares the current row count for one model (A) with another table B (that collects daily row counts for every table including A ). The current row count for table A must always be equal to or larger than the row count from the previous day for table A as stored in table B:

{% macro test_row_count_increasing(model) %}

    {% set current_row_count_query %}
        select count(*) as row_count from {{ model }} -- {{model}} is table A
    {% endset %}

    {% set current_row_count_results = run_query(current_row_count_query) %}
    {% set current_row_count = current_row_count_results.columns[0].values()[0] %}
 
    -- get the previous day row count from the B (rowcounts table)
    {% set previous_row_count_query %}
        select row_count from B 
        where "TABLE" = '{{ model }}' -- where "TABLE" = 'A'
        and TO_DATE("TIMESTAMP_UTC") = DATEADD(DAY, -1, CURRENT_DATE())  --snowflake SQL syntax
        and "DATABASE" = 'PROD_DWH'
    {% endset %}

    {% set previous_row_count_results = run_query(previous_row_count_query) %}
    {% set previous_row_count = previous_row_count_results.columns[0].values()[0] if previous_row_count_results.columns[0].values() else 0 %}
    
    {% if current_row_count  > previous_row_count %}   -- line 21
      {{print("Passed")}}  -- line 22
      {% else %} -- line 23
      {{print("Failed")}} --line 24
    {% endif %} -- line 25
{% endmacro %} -- line 26

The problem I’m having is when I run dbt test -s A
on my command line, I get the following error:

  Database Error in test row_count_increasing_A_ (models\prod_dwh\A\A.yml)
  001003 (42000): SQL compilation error:
  syntax error line 26 at position 4 unexpected ')'.
  compiled Code at target\run\SNOWFLAKE\models\prod_dwh\A\A.yml\row_count_increasing_A_.sql

When I look in this file compiled code location (target\run\SNOWFLAKE\models\prod_dwh\A\A.yml\row_count_increasing_A_.sql), I see below:

select
      count(*) as failures,
      count(*) != 0 as should_warn,
      count(*) != 0 as should_error
    from (
      

      
    ) dbt_internal_test

but no compiled code.

I would appreciate if someone could take a look at my code and tell me what I’m doing wrong.