# Lead Conversion by Source and Year

**Type:** SOQL · **Difficulty:** Hard · **Topics:** GROUP BY, Date Functions, HAVING

Practice this problem interactively (write and run your SOQL against realistic data): https://www.forcechallenges.com/problems/lead-conversion-by-source-year

## Problem

**Scenario**
Marketing wants to compare how well each lead source converts over time. Tiny groups are just noise, so only groups with a meaningful volume of Leads should be reported.

**Task**
Write one SOQL query on `Lead` that:
1. Groups Leads by `LeadSource`, by whether they were converted (`IsConverted`) and by the calendar year of `CreatedDate`.
2. Counts the Leads in each group.
3. Keeps only groups that contain **more than 10 Leads**.
4. Sorts the result by `LeadSource` ascending, then by year ascending.

**Expected output**
One row per group with four columns: `LeadSource`, `IsConverted`, `yr` (the calendar year) and `cnt` (the number of Leads).

**Example**
Suppose 2025 had 14 converted Web Leads and 6 unconverted Web Leads, and 2026 had 12 unconverted Partner Referral Leads.
- (Web, true, 2025) has 14 Leads, so it is returned.
- (Web, false, 2025) has only 6 Leads, so it is dropped.
- (Partner Referral, false, 2026) has 12 Leads, so it is returned.

Result: Partner Referral / false / 2026 / 12, then Web / true / 2025 / 14.

## Constraints

Use one aggregate query on Lead. Group by LeadSource, IsConverted and the calendar year of CreatedDate (CALENDAR_YEAR). Use HAVING for the volume filter. Alias the columns as `yr` and `cnt`.

---
Source: ForceChallenges · last updated 2026-10-23
