Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Power BI Revenue Before Publish

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Validate Power BI Revenue Before Publish. Start with the requirements and the four tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Business Context

You’re a data engineer supporting a fintech marketplace (≈2M monthly active users, ~$500M annual GMV). A Power BI dashboard used by Finance shows daily net revenue and is about to be published to executives. In the past, the team has shipped dashboards with subtle issues (double-counted refunds, missing FX conversion, and duplicated order lines), causing incorrect revenue reporting and rework.

The Power BI model is built from a curated table bi_daily_revenue produced by an ELT job. The source-of-truth lives in normalized operational tables: orders, order_items, and payments. Before publishing, you want to validate that the BI table matches the source-of-truth for a given date range.

Task

Write a SQL query that produces a day-level validation report for 2024-01-01 through 2024-01-03 comparing the Power BI table to the source-of-truth calculation.

Requirements

Your query must:

  1. Compute source-of-truth net revenue in USD per day as:
    • gross_usd = SUM(item_amount * fx_rate_to_usd) for all order items on that day
    • refunds_usd = SUM(refund_amount * fx_rate_to_usd) for payments with status = 'REFUNDED' on that day
    • net_usd = gross_usd - refunds_usd
  2. Avoid double counting due to multiple order items by aggregating items at the order level before joining to payments.
  3. Compare the source-of-truth to bi_daily_revenue.net_revenue_usd and output:
    • revenue_date, bi_net_usd, source_net_usd, diff_usd, diff_pct
  4. Include a data quality signal column validation_status with values:
    • OK if ABS(diff_usd) <= 1.00
    • MISMATCH otherwise
  5. Return one row per date in the range, ordered by revenue_date.

Schema

orders
ColumnTypeDescription
order_idPKINTUnique order identifier
user_idINTCustomer identifier
order_created_atTIMESTAMPOrder creation timestamp (UTC)
currencyVARCHAR(3)Order currency code
order_items
ColumnTypeDescription
order_item_idPKINTUnique order line identifier
order_idINTReferences orders.order_id
item_amountDECIMAL(10,2)Line item amount in order currency
payments
ColumnTypeDescription
payment_idPKINTUnique payment event identifier
order_idINTReferences orders.order_id
statusVARCHAR(20)Payment event status (e.g., CAPTURED, REFUNDED)
payment_created_atTIMESTAMPTimestamp of payment event (UTC)
amountDECIMAL(10,2)Payment amount in order currency
refund_amountDECIMAL(10,2)Refund amount in order currency (0 if none)
fx_rate_to_usdDECIMAL(12,6)FX rate to convert from order currency to USD at event time
bi_daily_revenue
ColumnTypeDescription
revenue_datePKDATERevenue date (UTC)
net_revenue_usdDECIMAL(12,2)Curated net revenue in USD used by Power BI
refreshed_atTIMESTAMPTimestamp when the BI aggregate was last refreshed
Tablesordersorder_itemspaymentsbi_daily_revenue
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results