Lab: Building MMR Analytics in Superset
Everything built in Superset follows the same four-step recipe: register a dataset, define a metric, turn the metric into a chart, and assemble charts into a dashboard. This lab applies that recipe end to end to the maternal mortality ratio, ending with the national Maternal Situational Analysis dashboard. Every chart on that dashboard was built exactly this way, so once the recipe is familiar it transfers to any other indicator.
- Register a maternal-events dataset in Superset and enrich it with case-level MPCDSR fields
- Write and save a reusable MMR metric as custom SQL, shared by every chart on the dashboard
- Turn the saved metric into a trend line chart and national big-number tiles
- Assemble charts into the nine-tab Maternal Situational Analysis dashboard
- Interpret the finished dashboard's descriptive and diagnostic findings
- Access to an Apache Superset instance connected to the data warehouse that holds the ingested maternal health data (DHIS2 + MPCDSR), with permission to create datasets, charts, and dashboards
- Completion of Analytics Foundations — this lab builds directly on the four analytics types and the four analytical questions introduced there
- Basic familiarity with SQL aggregate queries (
GROUP BY,FILTER/CASE,NULLIF)
Register the dataset
Start by deciding the required data elements, then register them in Superset as a Dataset — a physical table or a SQL view. The dataset becomes the single source that every chart queries, which is what keeps definitions consistent across the whole dashboard.
From DHIS2, the model needs:
- Live births — the denominator
- Maternal deaths — the numerator
- Cause of death
- Facility and facility type
- Province and district
- Date of death
Then enrich the dataset with case-level MPCDSR fields: the three delays, referral status, avoidability, age, and parity. The routine data gives the rates; the surveillance fields give the diagnostic depth.
Dataset: maternal_events
Columns (12)
live_births bigint
maternal_deaths bigint
cause_of_death varchar
facility varchar
facility_type varchar
province varchar
district varchar
date_of_death date
delay_1 / delay_2 / delay_3 varchar
referral_status varchar
avoidability varchar
age integer
parity integerNot seeing this?
- The MPCDSR fields (delays, referral status, avoidability) are missing — you registered the raw DHIS2 export before the enrichment join ran. Re-run the enrichment step, then re-sync the dataset columns in Superset.
live_birthsormaternal_deathsshow asvarcharinstead of a numeric type — fix the column type under Edit dataset → Columns, otherwise the MMR calculation below fails silently.
Estimating the MMR from routine data
The maternal mortality ratio is maternal deaths divided by live births, multiplied by 100,000. You can reach the same number two ways — prototype it in SQL Lab, or define it directly as a Superset metric on the dataset. Either way it becomes the one formula every chart on the dashboard reuses, so there’s no drift between charts.
SQL Lab
Run the full aggregate query against the registered dataset to check the numbers before saving anything:
-- Maternal Mortality Ratio (per 100,000 live births)
SELECT
year,
facility_type,
COUNT(*) FILTER (WHERE event = 'maternal_death') AS deaths,
COUNT(*) FILTER (WHERE event = 'live_birth') AS births,
ROUND(
COUNT(*) FILTER (WHERE event = 'maternal_death')::numeric
/ NULLIF(COUNT(*) FILTER (WHERE event = 'live_birth'), 0)
* 100000, 0
) AS mmr
FROM maternal_events
GROUP BY year, facility_type
ORDER BY year;The NULLIF guards against divide-by-zero where births are missing.
Metric: mmr (custom SQL)
Preview query result
year | facility_type | deaths | births | mmr
------+----------------+--------+---------+------
2019 | tertiary | 612 | 48,000 | 1275
2023 | tertiary | 354 | 48,000 | 737Not seeing this?
- The preview returns
mmr = NULLfor a row instead of a number — that facility_type/year has zero live births; confirm theNULLIFguard is in the saved metric SQL, not only in the ad-hoc query you tested. - The metric only shows up under “Simple” metrics, not “Custom SQL” — you saved it against the dataset’s default aggregate instead of pasting the SQL into Add metric → Custom SQL.
Turn the metric into a chart
Choose a chart type that matches the question. A trend question calls for a line chart; a ranking question calls for a bar chart; a single headline number calls for a big-number tile. Plotting the saved MMR metric by year for tertiary facilities, and as national big-number tiles, produces the headline figures:
| Figure | Value |
|---|---|
| Tertiary-facility MMR, start of the reporting period | 1,275 per 100,000 live births |
| Tertiary-facility MMR, end of the reporting period | 737 per 100,000 live births |
| Current national MMR | 77 per 100,000 live births |
| HSSP V ceiling for 2025/26 | 86 per 100,000 live births |
The tertiary-facility MMR falls steadily across the reporting period, and the national figure of 77 is tracking comfortably below the 86 ceiling set for 2025/26.
Line chart "Tertiary-facility MMR by year"
2019 ● 1,275 per 100,000 live births
2023 ● 737 per 100,000 live births
trend: downward
Big Number tile "National MMR" → 77 per 100,000 live births
Big Number tile "HSSP V ceiling" → 86 per 100,000 live birthsNot seeing this?
- The line chart is flat or shows a single point — the chart’s dimension is set to a column other than
year, or a filter left over from an earlier exploration still restricts it to one year. - The big-number tile shows a value far from 77 — it is querying the raw dataset instead of the saved
mmrmetric; re-point the chart’s metric field to the saved metric.
Assemble the dashboard
Finally, group the charts into dashboard tabs. The tabs of the Maternal Situational Analysis dashboard mirror the four analytical questions from the foundations session — from mortality overview through to circumstances of death and the care continuum.
| Tab | Analytical question it answers |
|---|---|
| Maternal Mortality | Overview — trend and headline MMR |
| Overview of Deliveries | Overview — delivery volumes behind the denominator |
| Regional Investigation | Overview — geographical and hospital distribution |
| Maternal Death Audit | Causes — direct vs indirect deaths by cause |
| Mother Characteristics | Associated factors — age, parity, risk profile |
| Circumstances of Death | Associated factors — delays, referral, avoidability |
| Facility Analysis | Overview and comparison — performance by facility and facility type |
| Surveillance | Comparison — routine figures against surveillance and survey estimates |
| ANC and PNC | Associated factors — care before and after delivery |
Dashboard: Maternal Situational Analysis
Tabs (9)
1. Maternal Mortality
2. Overview of Deliveries
3. Regional Investigation
4. Maternal Death Audit
5. Mother Characteristics
6. Circumstances of Death
7. Facility Analysis
8. Surveillance
9. ANC and PNCNot seeing this?
- Fewer than 9 tabs appear — a chart wasn’t assigned to a tab before publishing; open Edit dashboard and check every chart sits inside a tab, not floating outside all of them.
- A tab renders with no charts — the chart’s own filters don’t match the tab’s cross-filter (for example,
facility_typescoped to a value that excludes every row).
What the dashboard reveals
The finished dashboard delivers both of the analytics types the programme starts with.
Descriptive — what happened. Ranking direct obstetric deaths by cause shows that obstetric haemorrhage dominates, with 445 deaths — well ahead of hypertensive disorders (157), pregnancy-related infection (144), other complications (131), abortive outcomes (105), and unanticipated management (53).
Diagnostic — why it happened. The circumstances-of-death view shows that 81% of deaths were potentially avoidable, 72% occurred postpartum, 65% involved a high-risk pregnancy, and 97% of cases had been referred. Together, that is the evidence that drives action: deaths concentrate after delivery, most could have been prevented, and the referral pathway is where the system is under the greatest strain.
Next steps
From dashboard to decisions, four items carry the work forward:
- Finalise the DHIS2 data-element definitions with the M&E team.
- Validate the routine MMR against the DHS survey estimate.
- Extend the analytics to predictive forecasting toward the 86 target.
- Operationalise a monthly review of the dashboard with clinical and programme teams.