Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Validate Power BI Revenue Before Publish
00:00
5 left

Validate Power BI Revenue Before Publish

HardSQL · PostgreSQL

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
Interviewer

Your question is Validate Power BI Revenue Before Publish. Start with the requirements and the four tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.