NameCompanyStatusSourceValue

Rep Performance

RepDeals ClosedRevenueQuota Attainment
``` # FILE 2: `modelname_sales_analytics.html` ```html NexusCRM - Sales Analytics Engine

Sales Analytics Dashboard

Standardized SQL queries mapped to NexusCRM schema for pipeline, conversion, and rep performance tracking.

REFERENCE SCHEMA:
deals: id, title, contact_id, stage (enum), value, probability, close_date, owner_id, created_at, updated_at
contacts: id, name, company, status, source, created_at
sales_team: id, name, role, quota, status
pipeline_history: id, deal_id, previous_stage, current_stage, changed_at, changed_by
activities: id, deal_id, type, description, logged_at, owner_id
1. Pipeline Value by StageRevenue Forecasting
SELECT stage, COUNT(*) AS deal_count, SUM(value) AS total_pipeline_value, SUM(value * probability / 100) AS weighted_value FROM deals GROUP BY stage ORDER BY FIELD(stage, 'lead', 'qualified', 'proposal', 'negotiation', 'closed_won', 'closed_lost');
StageDealsTotal ValueWeighted Value
lead12$180,000$12,600
qualified8$340,000$102,000
proposal5$210,000$94,500
negotiation3$145,000$110,200
💡 Insight: Weighted value reveals true pipeline health. High total value with low probability indicates "paper deals" needing qualification.
2. Stage-to-Stage Conversion RatesFunnel Health
WITH stage_counts AS ( SELECT previous_stage, current_stage, COUNT(*) as transitions FROM pipeline_history WHERE changed_at >= NOW() - INTERVAL '90 days' GROUP BY previous_stage, current_stage ), stage_totals AS ( SELECT previous_stage, SUM(transitions) as total_from_stage FROM stage_counts GROUP BY previous_stage ) SELECT sc.previous_stage, sc.current_stage, sc.transitions, ROUND(sc.transitions * 100.0 / st.total_from_stage, 1) AS conversion_pct FROM stage_counts sc JOIN stage_totals st ON sc.previous_stage = st.previous_stage ORDER BY sc.previous_stage, conversion_pct DESC;
From StageTo StageTransitionsConversion %
leadqualified4562.5%
qualifiedproposal3871.2%
proposalnegotiation2288.0%
💡 Insight: Drop-offs >20% between stages indicate process bottlenecks. Focus training on stages with lowest conversion.
3. Average Deal Size & Sales CycleEfficiency Metrics
SELECT AVG(value) AS avg_deal_size, ROUND(AVG(DATEDIFF(updated_at, created_at)), 1) AS avg_sales_cycle_days, COUNT(*) AS closed_won_deals FROM deals WHERE stage = 'closed_won' AND close_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
Avg Deal SizeAvg Sales CycleDeals Closed
$84,20042 days34
💡 Insight: Track this quarterly. A shrinking cycle with stable deal size indicates improved qualification and faster ramp-up.
4. Sales Rep Performance ComparisonTeam Analytics
SELECT st.name, COUNT(d.id) AS deals_closed, SUM(d.value) AS total_revenue, COALESCE(st.quota, 0) AS annual_quota, ROUND(SUM(d.value) / st.quota * 100, 1) AS attainment_pct FROM deals d JOIN sales_team st ON d.owner_id = st.id WHERE d.stage = 'closed_won' AND close_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY st.id, st.quota ORDER BY attainment_pct DESC;
RepDealsRevenueQuotaAttainment
Sarah Chen18$1,420,000$1,200,000118.3%
Alex Rivera14$980,000$1,000,00098.0%
Mike Johnson11$745,000$900,00082.8%
💡 Insight: Attainment < 100% requires coaching or quota rebalancing. Compare activity volumes to identify effort gaps.
5. Forecast vs. Actual (This Quarter)Accuracy Tracking
SELECT 'Forecast' AS metric, ROUND(SUM(value * probability / 100), 2) AS projected_value FROM deals WHERE stage IN ('proposal', 'negotiation') AND close_date BETWEEN DATE_FORMAT(CURDATE(), '%Y-%m-01') AND LAST_DAY(CURDATE()) UNION ALL SELECT 'Actual' AS metric, ROUND(SUM(value), 2) AS projected_value FROM deals WHERE stage = 'closed_won' AND close_date BETWEEN DATE_FORMAT(CURDATE(), '%Y-%m-01') AND LAST_DAY(CURDATE());
MetricValue
Forecast$412,500
Actual$385,200
💡 Insight: Variance >10% flags forecasting inaccuracy. Adjust probability weights or implement stricter stage-gate criteria.
6. Lead Source EffectivenessROI Attribution
SELECT c.source, COUNT(d.id) AS total_deals, ROUND(AVG(d.value), 2) AS avg_deal_size, ROUND(SUM(CASE WHEN d.stage = 'closed_won' THEN 1 ELSE 0 END) * 100.0 / COUNT(d.id), 2) AS conversion_rate, SUM(CASE WHEN d.stage = 'closed_won' THEN d.value ELSE 0 END) AS total_revenue FROM contacts c LEFT JOIN deals d ON c.id = d.contact_id GROUP BY c.source HAVING total_deals >= 5 ORDER BY conversion_rate DESC;
SourceDealsAvg SizeConv. RateRevenue
referral24$92,40048.5%$892,000
webinar18$76,20033.2%$456,000
linkedin31$54,80019.8%$338,000
cold42$41,20012.4%$218,000
💡 Insight: Allocate budget to high-conversion/high-AOV sources. Cold outreach may need list refinement or messaging overhaul.