# dbt jinja conditional logic

**URL:** <https://discourse.getdbt.com/t/dbt-jinja-conditional-logic/14060>\
**Category:** Help\
**Created:** [July 4, 2024, 7:52pm UTC](https://discourse.getdbt.com/t/dbt-jinja-conditional-logic/14060 "2024-07-04T19:52:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ace](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@ace](https://discourse.getdbt.com/u/ace)\
**Post date:** [July 4, 2024, 7:52pm UTC](https://discourse.getdbt.com/t/dbt-jinja-conditional-logic/14060/1 "2024-07-04T19:52:34Z")

</div>

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:

```auto
{% 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:

```auto
  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:

```auto
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.
