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:
LeadSource, by whether they were converted (IsConverted) and by the calendar year of CreatedDate.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.
Result: Partner Referral / false / 2026 / 12, then Web / true / 2025 / 14.
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.
6 row(s), order checked
| # | yr | cnt | LeadSource | IsConverted |
|---|---|---|---|---|
| 1 | 2027 | 12 | Partner Referral | false |
| 2 | 2027 | 12 | Partner Referral | true |
| 3 | 2027 | 12 | Phone Inquiry | true |
| 4 | 2027 | 12 | Phone Inquiry | false |
| 5 | 2027 | 12 | Web | true |
| 6 | 2027 | 13 | Web | false |