Closed won deals by owner
Retrieves the number of closed won deals by owner from HubSpot and orders them in descending order based on the number of deals.
- Grain
- See the notes
- Built from
- 2Raw tables
- 1Core
- 1Analytics
- Reads from HubSpot
- dealsowners
- Ships as
- Weld and dbt SQL, open source on GitHub
1-- core.hubspot.closed_won_deals_by_owner
2-- Closed won deals by owner. Retrieves the number of closed won deals by owner from
3-- HubSpot and orders them in descending order based on the number of deals.
4--
5-- From the weld.app template library. Not reconciled against HubSpot;
6-- check the output against the source before relying on it.
7
8select
9concat(owners.firstName, ' ', owners.lastName) as deal_owner,
10count(*) as number_of_deals
11from
12{{raw.hubspot.deals}} as deals
13left join {{raw.hubspot.owners}} as owners on cast(owners.id as int) = deals.properties_hubspot_owner_id
14where
15properties_dealstage = 'closedwon'
16group by
17deal_owner
18order by
19number_of_deals descThis model and the 1 it depends on. Deploy them together; refs like {{staging.…}} resolve to the matching folders in Weld, and the dbt view uses source() and ref().
How it counts. And where it stops.
This SQL model allows you to easily track the number of closed won deals by each owner in your organization. By running this SQL, you can quickly gain insights into which sales reps are performing the best and which ones may need additional support. The SQL code uses a left join to combine data from the HubSpot deals and owners tables, and then filters the results to only show deals that have been marked as "closedwon". The output of the SQL is a table that displays the name of each deal owner and the number of closed won deals they have. This information can be used to identify top performers, set sales goals, and optimize your sales process.
Raw tables it reads
- raw.hubspot.deals
- raw.hubspot.owners
Put HubSpot in front
of your agents.
Connect HubSpot, deploy the models, and ask questions in Claude, Cursor or ChatGPT. Free for 14 days, no credit card.