Scenario The finance team reports revenue to the board every quarter. Only deals that were actually won count as revenue, and the quarter is determined by the date the deal closed, not when it was created.
Task
Write one SOQL query on Opportunity that:
IsWon = true).CloseDate.Amount for each year and quarter.Expected output
One row per quarter that has won revenue, with three columns: yr (calendar year), qtr (quarter number 1 to 4) and revenue (sum of Amount). Quarters with no won deals do not appear.
Example Won deals: 100,000 closed on 10 Feb 2025, 50,000 closed on 20 Mar 2025, 70,000 closed on 5 Jul 2025. A 90,000 deal closed on 1 Feb 2025 was Closed Lost.
Result: 2025 / 1 / 150,000, then 2025 / 3 / 70,000.
Use one aggregate query on Opportunity. Filter with IsWon = true. Group by CALENDAR_YEAR(CloseDate) and CALENDAR_QUARTER(CloseDate), and order by the same two expressions ascending. Alias the columns exactly as yr, qtr and revenue.
8 row(s), order checked
| # | yr | qtr | revenue |
|---|---|---|---|
| 1 | 2024 | 3 | 8950000 |
| 2 | 2024 | 4 | 53300000 |
| 3 | 2025 | 1 | 44850000 |
| 4 | 2025 | 2 | 36400000 |
| 5 | 2025 | 3 | 27950000 |
| 6 | 2025 | 4 | 19500000 |
| 7 | 2026 | 1 | 11050000 |
| 8 | 2026 | 2 | 2750000 |