Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.