Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Slowly Changing Dimensions Handling
00:00
5 left

Slowly Changing Dimensions Handling

HardSQL · PostgreSQL

Problem

What’s your approach to handling slowly changing dimensions or historical reporting in a dashboard model?

Write a PostgreSQL query that attributes each sale to the dimension version valid on the sale date, then produces the requested historical reporting output.

Output

  1. One row per reported month and service line, including only service lines with sales.
  2. Columns: report_month, service_line, monthly_revenue, previous_reported_revenue, and revenue_change.
  3. Sort by service_line, then report_month ascending.

Schema

employee_dimension
ColumnTypeDescription
employee_skPKINTSurrogate key for a dimension version
employee_idVARCHAR(10)Stable employee business key
employee_nameVARCHAR(100)Employee name for the dimension version
service_lineVARCHAR(50)Service line assigned during the effective period
effective_fromDATEInclusive start date of the dimension version
effective_toDATEExclusive end date, or NULL for the current version
sales_fact
ColumnTypeDescription
sale_idPKINTUnique sale identifier
employee_idVARCHAR(10)Employee business key associated with the sale
sale_dateDATEDate on which the sale occurred
revenueNUMERIC(12,2)Revenue recognized for the sale
Tablesemployee_dimensionsales_fact
Interviewer

Your question is Slowly Changing Dimensions Handling. Start with the requirements and the two 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.