# Monthly Pipeline Created by Stage

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

Practice this problem interactively (write and run your SOQL against realistic data): https://www.forcechallenges.com/problems/monthly-pipeline-created-by-stage

## Problem

**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:
1. Groups Opportunities by the calendar **year** and **month** of `CreatedDate` and by `StageName`.
2. Sums the `Amount` in each group.
3. Keeps only groups whose total `Amount` is **greater than 500,000**.
4. Sorts by year, then month, then `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.
- (2026, 3, Proposal) totals 700,000, so it is returned.
- (2026, 3, Prospecting) totals 200,000, so it is dropped.
- (2026, 4, Proposal) totals 600,000, so it is returned.

Result: 2026 / 3 / Proposal / 700,000, then 2026 / 4 / Proposal / 600,000.

## Constraints

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.

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