Provider Analytics Path · Mission 18 of 25Hard

Month-over-month encounter trend

Use LAG() window function for period-over-period comparison

Back to Provider Analytics

The Brief

Dr. Amara OkaforChief Quality Officerquality-analytics

Show me monthly encounter volume with month-over-month change as a percentage. I want to see if we're trending up or down. Also — exclude encounters from the provider with the future hire date. That data is suspect and I don't want it in the trend.

You'll practice

LAG()Date extraction% change

Tables & columns available

fact_encountersfact10 columns
ColumnTypeKey
encounter_idINTPK
patient_idINTFK → dim_patients
provider_idINTFK → dim_providers
department_idINTFK → dim_departments
admit_dateTEXT
discharge_dateTEXT
diagnosis_codeTEXT
diagnosis_descriptionTEXT
encounter_typeTEXT
discharge_dispositionTEXT
dim_providersdim7 columns
ColumnTypeKey
provider_idINTPK
first_nameTEXT
last_nameTEXT
specialtyTEXT
department_idINTFK → dim_departments
hire_dateTEXT
is_activeINT

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Aggregate monthly counts first. Then a window function that looks one row back chronologically gives you the prior month's count

Hint 2

Exclude the suspect provider with the future hire_date before aggregating, then compute MoM % from the current and lagged counts

Hint 3

`LAG(encounter_count, ___) OVER (ORDER BY ___, ___) AS prior_count` — then `ROUND(100.0 * (encounter_count - prior_count) / ___, 1) AS mom_change_pct`