Write a SQL query to calculate monthly KPI trends with year-over-year comparison for Volvo Group.
Use completed deliveries for valid Volvo Group vehicle models sold through active dealer locations. Include months with no prior-year comparison, and calculate delivery volume, revenue, revenue per vehicle, and year-over-year percentage changes.
Output
- One row per calendar month with columns
month_start, delivered_units, total_revenue, revenue_per_vehicle, prior_year_units, prior_year_revenue, units_yoy_pct, and revenue_yoy_pct.
- Include all qualifying months, sort chronologically, and return NULL percentage values when no prior-year baseline exists or the baseline is zero.
Output details
- Filter deliveries to records whose status is exactly
Delivered.
- Count each qualifying delivery row as one
delivered_units.
- Sum qualifying
net_revenue values for total_revenue, reported to two decimal places.
- Calculate
revenue_per_vehicle as total revenue divided by delivered units, rounded to two decimal places.
- Compare each month with the same calendar month one year earlier.
- Round both year-over-year percentage values to two decimal places and sort months ascending.