# Power BI implementation guide

This guide turns the prepared tables in `analytics/data/powerbi/` into a Power BI model that reproduces the website's dashboard.

**Status, stated plainly.** The CSV tables are generated and tested. The DAX below follows standard patterns but was **not executed in Power BI Desktop**, because Desktop was not available in the build environment. No `.pbix` file is shipped for that reason. The validation table at the end lists the values each measure should return, taken from the tested pandas and SQL pipelines, so the model can be checked in a few minutes once built.

## 1. Load the tables

Get Data > Text/CSV, one file per table. Set every `*_date`, `month_end` and `date` column to type Date. Empty date strings load as blank.

| Table | Role | Grain |
|---|---|---|
| `dim_system` | Dimension | One row per AI system, with business unit, owner and model attributes denormalized |
| `dim_control` | Dimension | One row per control |
| `dim_date` | Dimension | One row per calendar day, May 2025 to Dec 2026. Mark as date table on `date` |
| `fact_control_tests` | Fact | One row per control test; `passed` is 0 or 1 |
| `fact_findings` | Fact | One row per finding; `is_open`, `is_overdue`, `age_days`, `aging_bucket`, `closed_within_sla` are precomputed as of 2026-10-31 |
| `fact_remediation_actions` | Fact | One row per remediation action |
| `fact_evidence` | Fact | One row per evidence record; `is_current` as of 2026-10-31 |
| `fact_exceptions` | Fact | One row per exception with `status` |
| `fact_incidents` | Fact | One row per incident |
| `fact_incident_refunds` | Fact | One row per refund behind incident INC-0031. Relate to `fact_incidents[incident_id]` only if you build an incident detail page |
| `fact_model_changes` | Fact | One row per change and affected system with `status` |
| `fact_system_month` | Snapshot fact | One row per live system per month end: required, implemented, effective and evidence-current control counts, open findings and residual tier |
| `bridge_system_control` | Bridge | Required controls per system |

## 2. Relationships (star schema)

All single direction, one to many, from dimension to fact.

| From (one) | To (many) | Active |
|---|---|---|
| `dim_system[system_id]` | every fact and bridge table `[system_id]` | Yes |
| `dim_control[control_id]` | `fact_control_tests`, `fact_evidence`, `fact_findings`, `fact_exceptions`, `bridge_system_control` | Yes |
| `dim_date[date]` | `fact_control_tests[test_date]` | Yes |
| `dim_date[date]` | `fact_findings[opened_date]` | Yes |
| `dim_date[date]` | `fact_findings[closed_date]` | No (use `USERELATIONSHIP`) |
| `dim_date[date]` | `fact_incidents[detected_date]` | Yes |
| `dim_date[date]` | `fact_system_month[month_end]` | Yes |
| `dim_date[date]` | `fact_model_changes[change_date]` | Yes |
| `fact_findings[finding_id]` | `fact_remediation_actions[finding_id]` | Yes |

Sort `dim_system[inherent_tier]` by `tier_sort`. Sort `dim_date[month_label]` by `month`.

## 3. Why a monthly snapshot table

Coverage, effectiveness, evidence currency and residual risk are point-in-time positions. Each depends on the latest test in a 210-day window, the evidence valid on a date, and the findings open on that date. Computing that in DAX for every month is possible but slow and hard to audit. `prepare_data.py` computes it once per month end and writes `fact_system_month`, so the DAX stays simple and the logic lives in one tested place. Snapshot measures are **semi-additive**: they sum across systems but must not be summed across months.

## 4. DAX measures

```dax
-- Helper: the last month end in the current filter context
Last Month End = MAX ( fact_system_month[month_end] )

-- Semi-additive bases: take the last month end, then sum across systems
Required Controls =
VAR LastEnd = [Last Month End]
RETURN CALCULATE ( SUM ( fact_system_month[required] ), fact_system_month[month_end] = LastEnd )

Implemented Controls =
VAR LastEnd = [Last Month End]
RETURN CALCULATE ( SUM ( fact_system_month[implemented] ), fact_system_month[month_end] = LastEnd )

Effective Controls =
VAR LastEnd = [Last Month End]
RETURN CALCULATE ( SUM ( fact_system_month[effective] ), fact_system_month[month_end] = LastEnd )

Controls With Current Evidence =
VAR LastEnd = [Last Month End]
RETURN CALCULATE ( SUM ( fact_system_month[evidence_current] ), fact_system_month[month_end] = LastEnd )

Live Systems =
VAR LastEnd = [Last Month End]
RETURN CALCULATE ( DISTINCTCOUNT ( fact_system_month[system_id] ), fact_system_month[month_end] = LastEnd )

-- The three control measures, kept separate on purpose
Control Coverage % = DIVIDE ( [Implemented Controls], [Required Controls] )
Control Effectiveness % = DIVIDE ( [Effective Controls], [Required Controls] )
Evidence Currency % = DIVIDE ( [Controls With Current Evidence], [Required Controls] )

-- Flow measure: tests executed in the period
Tests Run = COUNTROWS ( fact_control_tests )
Test Pass Rate % = DIVIDE ( SUM ( fact_control_tests[passed] ), [Tests Run] )

-- Residual risk distribution
High or Critical Residual Systems =
VAR LastEnd = [Last Month End]
RETURN
    CALCULATE (
        DISTINCTCOUNT ( fact_system_month[system_id] ),
        fact_system_month[month_end] = LastEnd,
        fact_system_month[residual_tier] IN { "High", "Critical" }
    )

-- Findings (as of the dataset date, using precomputed flags)
Open Findings = CALCULATE ( COUNTROWS ( fact_findings ), fact_findings[is_open] = 1 )
Open Critical Findings = CALCULATE ( [Open Findings], fact_findings[severity] = "Critical" )
Overdue Findings = CALCULATE ( COUNTROWS ( fact_findings ), fact_findings[is_overdue] = 1 )

Findings Opened = COUNTROWS ( fact_findings )
Findings Closed =
CALCULATE (
    COUNTROWS ( fact_findings ),
    USERELATIONSHIP ( dim_date[date], fact_findings[closed_date] ),
    NOT ISBLANK ( fact_findings[closed_date] )
)
Closed Within SLA % =
DIVIDE (
    CALCULATE ( SUM ( fact_findings[closed_within_sla] ), fact_findings[is_open] = 0 ),
    CALCULATE ( COUNTROWS ( fact_findings ), fact_findings[is_open] = 0 )
)
Avg Days to Close = CALCULATE ( AVERAGE ( fact_findings[age_days] ), fact_findings[is_open] = 0 )

-- Incidents with a trailing three-month average to separate a spike from noise
Incidents = COUNTROWS ( fact_incidents )
Incidents Prior 3M Avg =
VAR PeriodStart = MIN ( dim_date[date] )
RETURN
    DIVIDE (
        CALCULATE ( [Incidents], DATESINPERIOD ( dim_date[date], PeriodStart - 1, -3, MONTH ) ),
        3
    )

-- Reviews, exceptions, reassessments, agents
Overdue Reviews = CALCULATE ( COUNTROWS ( dim_system ), dim_system[review_overdue] = 1 )
Exceptions Past Expiry = CALCULATE ( COUNTROWS ( fact_exceptions ), fact_exceptions[status] = "Expired, not closed" )
Reassessments Pending = CALCULATE ( COUNTROWS ( fact_model_changes ), fact_model_changes[status] IN { "Pending", "Overdue" } )
Reassessments Overdue = CALCULATE ( COUNTROWS ( fact_model_changes ), fact_model_changes[status] = "Overdue" )
High-Risk Agents = CALCULATE ( COUNTROWS ( dim_system ), dim_system[is_high_risk_agent] = 1, dim_system[is_live] = 1 )
```

Notes on scope: `fact_findings`, `fact_exceptions` and `fact_model_changes` include retired systems. The website's headline figures count live systems only, so add the filter `dim_system[is_live] = 1` to a page or to the measure when reproducing them.

## 5. Suggested report pages

1. **Leadership attention.** A table of systems with open Critical findings, overdue reviews or overdue reassessments, showing owner and accountable executive. Cards for the eight headline measures.
2. **Risk.** Inherent against residual tier (100% stacked bar from `dim_system[inherent_tier]` and `fact_system_month[residual_tier]`), and residual tier by month.
3. **Controls.** Coverage, effectiveness and evidence currency by business unit; test pass rate by month; a matrix of control domain by result.
4. **Findings.** Aging bucket by severity, opened against closed by month, SLA performance.
5. **Change.** Model changes by type with pending and overdue reassessments.

Add slicers for business unit, inherent tier, owner and system, and enable drill-through from any visual to a system detail page keyed on `dim_system[system_id]`.

## 6. Validation targets

With a page filter of `dim_system[is_live] = 1` and the date context at October 2026, the measures should return:

| Measure | Expected |
|---|---|
| Live Systems | 50 |
| Required Controls | 693 |
| Implemented Controls | 660 |
| Effective Controls | 564 |
| Controls With Current Evidence | 633 |
| Control Coverage % | 95.2% |
| Control Effectiveness % | 81.4% |
| Evidence Currency % | 91.3% |
| Open Findings | 19 |
| Open Critical Findings | 5 |
| Overdue Findings | 7 |
| Overdue Reviews | 8 |
| Reassessments Pending | 16 |
| Reassessments Overdue | 5 |

These come from `analytics/output/metrics_snapshot.json` and are the same values `tests/reconcile.test.js` checks against the website engine and the SQL queries. If the dataset is regenerated with a different seed, read the new targets from that file.
