Skip to content

4. Daily Revenue for a Reporting Window

Difficulty: Easy · Topic: Jinja, vars & packages

Finance reruns the daily revenue report for different periods by passing dates on the command line: dbt run --vars '{start_date: "2024-03-01", end_date: "2024-03-31"}'.

Write daily_revenue from {{ ref('fct_orders') }}: one row per day that has orders between var('start_date') and var('end_date'), both inclusive, with order_date, orders (count) and revenue (sum of amount).

The hidden tests pass different dates, so they must come from the vars.

Your model is compiled like dbt does and run in DuckDB against 3 test cases, including hidden edge cases.

Sample inputs

{{ ref('fct_orders') }}

order_idordered_onamount
12024-02-2910
22024-03-0120
32024-03-015.5
42024-03-037.25
52024-03-04100

Expected output

order_dateordersrevenue
2024-03-01225.5
2024-03-0317.25

Hints

Hint 1{{ var('start_date') }} renders the raw text 2024-03-01, without quotes. Put it inside a SQL string: '{{ var("start_date") }}'.
Hint 2between includes both ends. With < instead, the last day of the window disappears.

More dbt problems

All dbt problems