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.
metric_name, period, target_value, actual_value, critical_threshold_pct, variance_value, variance_pct, and formatting_statusmetric_name, then periodmetric_name and period in ascending order.variance_value only when both target_value and actual_value are non-NULL; otherwise return NULL.variance_pct as ROUND(100 * variance_value / ABS(target_value), 2) unless either value is NULL or target_value is zero, then return NULL.UNMAPPED_ACTUAL, NULL actuals as MISSING_ACTUAL, and zero targets as NO_BASELINE.CRITICAL only when ABS(variance_value) / ABS(target_value) is strictly greater than critical_threshold_pct; otherwise label it OK.metric_name and period without deduplication.| Column | Type | Description |
|---|---|---|
| target_idPK | INT | Unique target record identifier |
| metric_name | VARCHAR(100) | Metric being monitored |
| period | DATE | Reporting period |
| target_value | NUMERIC(12,2) | Expected metric value |
| critical_threshold_pct | NUMERIC(6,4) | Critical variance threshold as a decimal fraction |
| Column | Type | Description |
|---|---|---|
| actual_idPK | INT | Unique actual record identifier |
| metric_name | VARCHAR(100) | Observed metric name |
| period | DATE | Observed reporting period |
| actual_value | NUMERIC(12,2) | Observed metric value |