diff --git a/macros/select_date_range.sql b/macros/select_date_range.sql new file mode 100644 index 00000000..56c7acce --- /dev/null +++ b/macros/select_date_range.sql @@ -0,0 +1,7 @@ +{% macro select_date_range(start_date, end_date, date_column) %} + {% if start_date is not none and end_date is not none %} + date_column >= start_date and date_column <= end_date + {% else %} + date_column >= CURRENT_DATE - var("lookback_window") + {% endif %} +{% endmacro %} \ No newline at end of file diff --git a/models/staging/base/base_ga4__events.sql b/models/staging/base/base_ga4__events.sql index 5ad001ea..1a719f58 100644 --- a/models/staging/base/base_ga4__events.sql +++ b/models/staging/base/base_ga4__events.sql @@ -22,6 +22,9 @@ with source as ( {{ ga4.base_select_source() }} from {{ source('ga4', 'events') }} where cast(left(replace(_table_suffix, 'intraday_', ''), 8) as int64) >= {{var('start_date')}} + {% if end_date is not none %} + and cast(left(replace(_table_suffix, 'intraday_', ''), 8) as int64) <= {{ end_date }} + {% endif %} {% if is_incremental() %} and parse_date('%Y%m%d', left(replace(_table_suffix, 'intraday_', ''), 8)) in ({{ partitions_to_replace | join(',') }}) {% endif %}