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
Programmatic Conditional Formatting
00:00
5 left

Programmatic Conditional Formatting

MediumSQL · PostgreSQL

Problem

Can you explain how conditional formatting can be applied programmatically to highlight critical variances in a dataset?

For this SQL implementation, return each target metric with its actual value, variance, percentage variance, and a status label based on the configured threshold. Include missing targets or actuals and handle zero targets explicitly.

Output

  1. One row per metric and reporting period, including unmatched records from either table
  2. Columns: metric_name, period, target_value, actual_value, critical_threshold_pct, variance_value, variance_pct, and formatting_status
  3. Sort by metric_name, then period

Schema

metric_targets
ColumnTypeDescription
target_idPKINTUnique target record identifier
metric_nameVARCHAR(100)Metric being monitored
periodDATEReporting period
target_valueNUMERIC(12,2)Expected metric value
critical_threshold_pctNUMERIC(6,4)Critical variance threshold as a decimal fraction
metric_actuals
ColumnTypeDescription
actual_idPKINTUnique actual record identifier
metric_nameVARCHAR(100)Observed metric name
periodDATEObserved reporting period
actual_valueNUMERIC(12,2)Observed metric value
Tablesmetric_targetsmetric_actuals
Interviewer

Your question is Programmatic Conditional Formatting. 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.