Closes by Month

Advanced

A 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

NameStageNameAmountCloseDate
AProspecting1,0002026-01-15
BProspecting2,0002026-01-30
CProspecting3,0002026-03-02
DClosed Won4,0002025-03-20
EProspecting5,0002026-12-01

Expected result on the sample

closeMonthtotal
12
32
121

Row order does not matter. Only the columns above are compared; extra columns in your SELECT are fine.

Hints
  • CALENDAR_MONTH(CloseDate) closeMonth in 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.

SOQL

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.