Biggest Open Deal per Stage

Intermediate

Sales managers review the single largest deal still in play at each stage of the pipeline.

For Opportunities that are still open, return each StageName with the largest Amount, aliased biggest.

Sample data

Opportunity 4 records

NameStageNameAmountCloseDate
AProspecting20,000today + 30 days
BProspecting45,000today + 30 days
CNegotiation/Review80,000today + 30 days
DClosed Won500,000today + 30 days

Expected result on the sample

StageNamebiggest
Prospecting45,000
Negotiation/Review80,000

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

Hints
  • IsClosed = false keeps open deals.
  • MAX(Amount) biggest, grouped by stage.

What this tests

IsClosed is set from the stage configuration, so filtering on it keeps working when an admin adds or renames closed stages, where a hard-coded list of stage names would not. MAX, MIN, SUM and AVG all ignore nulls, so a deal with no amount never wins MAX.

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.