Scenario Finance tracks how much pipeline the sales team creates each month and in which stage it currently sits. Small month and stage combinations are noise in the report, so only the large ones should appear.
Task
Write one SOQL query on Opportunity that:
CreatedDate and by StageName.Amount in each group.Amount is greater than 500,000.StageName (all ascending).Expected output
One row per group with four columns: yr (calendar year), mo (calendar month number), StageName and total (sum of Amount).
Example Opportunities created in March 2026: Proposal 300,000 + 400,000 and Prospecting 200,000. Opportunities created in April 2026: Proposal 600,000.
Result: 2026 / 3 / Proposal / 700,000, then 2026 / 4 / Proposal / 600,000.
Use one aggregate query on Opportunity. Group by CALENDAR_YEAR(CreatedDate), CALENDAR_MONTH(CreatedDate) and StageName. Filter the groups with HAVING on SUM(Amount). Alias the columns exactly as yr, mo and total. Order by year, month, then StageName.
29 row(s), order checked
| # | mo | yr | total | StageName |
|---|---|---|---|---|
| 1 | 4 | 2025 | 1200000 | Negotiation/Review |
| 2 | 4 | 2025 | 1180000 | Proposal |
| 3 | 5 | 2025 | 1140000 | Negotiation/Review |
| 4 | 5 | 2025 | 1120000 | Proposal |
| 5 | 5 | 2025 | 2260000 | Prospecting |
| 6 | 6 | 2025 | 2100000 | Negotiation/Review |
| 7 | 6 | 2025 | 2060000 | Proposal |
| 8 | 6 | 2025 | 1040000 | Prospecting |
| 9 | 7 | 2025 | 960000 | Negotiation/Review |
| 10 | 7 | 2025 | 940000 | Proposal |
| 11 | 7 | 2025 | 1900000 | Prospecting |
| 12 | 8 | 2025 | 1740000 | Negotiation/Review |
| 13 | 8 | 2025 | 880000 | Proposal |
| 14 | 8 | 2025 | 860000 | Prospecting |
| 15 | 9 | 2025 | 780000 | Negotiation/Review |
| 16 | 9 | 2025 | 1580000 | Proposal |
| 17 | 9 | 2025 | 1540000 | Prospecting |
| 18 | 10 | 2025 | 1380000 | Negotiation/Review |
| 19 | 10 | 2025 | 700000 | Proposal |
| 20 | 10 | 2025 | 680000 | Prospecting |
| 21 | 11 | 2025 | 600000 | Negotiation/Review |
| 22 | 11 | 2025 | 1220000 | Proposal |
| 23 | 11 | 2025 | 620000 | Prospecting |
| 24 | 12 | 2025 | 1020000 | Negotiation/Review |
| 25 | 12 | 2025 | 520000 | Proposal |
| 26 | 12 | 2025 | 1060000 | Prospecting |
| 27 | 1 | 2026 | 860000 | Proposal |
| 28 | 2 | 2026 | 700000 | Prospecting |
| 29 | 3 | 2026 | 540000 | Negotiation/Review |