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