Skip to content

Delivered revenue in USD with as-of exchange rates

HardFull bankAnalytics engineeringDeduplication and latest rowJoins25 min2 hidden datasets

The task

Finance reports delivered revenue in US dollars by the month orders were placed. Build it from the raw order load.

  • Use each order's current copy (latest updated_at) for its status and order_total. Count only orders whose current status is delivered.
  • An order was placed on the date of its earliest updated_at.
  • Convert EUR and GBP totals with fx_rates, using the rate on the placement date. When there is no rate that day (weekends and market holidays), use the most recent earlier rate. USD totals need no conversion.

Return month (the first day of the placement month), delivered_orders and usd_revenue (the converted totals added up, rounded to 2 decimal places). Sort by month.

Expected output

monthdelivered_ordersusd_revenue
  • Sorted by month ascending.
  • Numbers rounded to 2 decimal places.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Analytics warehouse · click a name to insert it

stg_orders669 rows in the sample

Raw order rows as loaded from the source. The same order can arrive several times: each change in the source sends a new copy, and some loads repeat a copy exactly.

intOrder id from the source.
intCustomer id.
numeric(10,2)Order total in the order currency.
textUSD, EUR or GBP.
textplaced, shipped, delivered or cancelled.
timestampWhen the source last changed this order (UTC).
timestampWhen our pipeline loaded this copy (UTC).
dim_customers_history120 rows in the sample

Type 2 history: one row per version of a customer. A version is valid from valid_from up to, not including, valid_to. Key: customer_id, valid_from.

intCustomer id.
textName.
textbronze, silver or gold.
textEMEA, AMER or APAC.
timestampStart of this version (UTC).
timestampEnd of this version (not included). NULL for the current version.
fx_rates254 rows in the sample

Closing exchange rates on business days only (no weekend rows). Key: rate_date, currency.

dateBusiness day.
textEUR or GBP.
numeric(12,6)US dollars for one unit of the currency.
inventory_snapshots336 rows in the sample

Stock on hand per product at the end of each day. A product missing from a day had no snapshot taken. Key: snapshot_date, sku.

dateDay of the snapshot.
textProduct code.
intUnits in stock.

Related questions

Loading the editor and PostgreSQL