Closes by Month
Advanced SolvedA seasonality chart shows how many deals close in each month of the year, across all years.
Count Opportunities by the calendar month of their CloseDate. Return the month number aliased closeMonth and the count aliased total.
Sample data
Opportunity 5 records
| Name | StageName | Amount | CloseDate |
|---|---|---|---|
| A | Prospecting | 1,000 | 2026-01-15 |
| B | Prospecting | 2,000 | 2026-01-30 |
| C | Prospecting | 3,000 | 2026-03-02 |
| D | Closed Won | 4,000 | 2025-03-20 |
| E | Prospecting | 5,000 | 2026-12-01 |
Expected result on the sample
| closeMonth | total |
|---|---|
| 1 | 2 |
| 3 | 2 |
| 12 | 1 |
Row order does not matter. Only the columns above are compared; extra columns in your SELECT are fine.
Hints
CALENDAR_MONTH(CloseDate) closeMonthin SELECT.- Group by the same function, not by the alias.
What this tests
Date functions such as CALENDAR_MONTH, CALENDAR_YEAR and DAY_ONLY let you group by part of a date in the query itself. Grouping by month number on its own merges the same month from different years, which is the point of a seasonality view. Add CALENDAR_YEAR to the GROUP BY when you need them apart.
Datasets
Solved on this device only. Sign in with Google to keep your progress across devices.
Run on sample executes your query against the sample data shown on the left and displays the rows it returns. Submit checks it against the sample plus 2 hidden datasets, comparing your rows with the expected rows on each. Queries run in a real Salesforce org; the data is inserted for your run and rolled back afterwards.