How to Build an AI-Powered Win/Loss Analysis System
Analyze won and lost deals with AI to find patterns and improve close rates.
Jay Banlasan
The AI Systems Guy
You can not improve what you do not measure. An ai win loss analysis of your sales deals turns closed deals into a playbook. I run this quarterly for clients and it consistently reveals why deals die. The patterns are always there.
What You Need Before Starting
- Python 3.8+
- Claude or GPT API key
- CRM with deal history and notes
- pandas installed
Step 1: Export Win/Loss Data
Pull all closed deals from the last 12 months with notes and timeline data.
import pandas as pd
def export_closed_deals(crm_client, months=12):
deals = crm_client.get_deals(
status=["won", "lost"],
date_range=f"last_{months}_months",
include=["notes", "activities", "timeline"]
)
df = pd.DataFrame(deals)
df["outcome"] = df["status"].map({"won": 1, "lost": 0})
return df
Step 2: Analyze with AI
Feed deal summaries to Claude. The AI finds themes humans miss across hundreds of deals.
import anthropic
def analyze_deals(lost_deals):
client = anthropic.Anthropic()
summaries = ""
for _, deal in lost_deals.head(50).iterrows():
summaries += f"Deal: {deal['name']}, Value: ${deal['amount']:,.0f}, "
summaries += f"Stage Lost: {deal['lost_stage']}, Notes: {deal['notes']}\n\n"
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=2000,
messages=[{
"role": "user",
"content": f"Analyze these lost deals. Identify the top 5 patterns.\n\n{summaries}"
}]
)
return message.content[0].text
Step 3: Build the Comparison Matrix
Compare won vs lost deals across key dimensions.
def build_comparison(df):
comparison = {}
for metric in ["amount", "cycle_days", "meetings_held", "stakeholders"]:
comparison[metric] = {
"won_avg": df[df["outcome"] == 1][metric].mean(),
"lost_avg": df[df["outcome"] == 0][metric].mean(),
}
return comparison
Step 4: Generate the Report
Combine quantitative analysis with AI insights into one actionable document.
def generate_report(comparison, ai_analysis, output_path):
report = "# Win/Loss Analysis Report\n\n"
report += "| Metric | Won (Avg) | Lost (Avg) |\n"
report += "|--------|-----------|------------|\n"
for metric, data in comparison.items():
report += f"| {metric} | {data['won_avg']:.1f} | {data['lost_avg']:.1f} |\n"
report += f"\n## Pattern Analysis\n\n{ai_analysis}\n"
with open(output_path, "w") as f:
f.write(report)
Step 5: Track Quarterly Improvements
Run the analysis quarterly. Compare loss patterns over time.
def track_trends(current_quarter, previous_quarters):
loss_rates = []
for q in previous_quarters + [current_quarter]:
total = len(q)
lost = len(q[q["outcome"] == 0])
loss_rates.append({
"quarter": q["quarter"].iloc[0],
"loss_rate": lost / max(total, 1),
})
return loss_rates
What to Build Next
Feed your win/loss patterns back into your battle cards and sales training. The analysis is useless if it stays in a report nobody reads.
Related Reading
- Creating Automated Win-Loss Analysis - automated win loss analysis guide
- AI for Customer Retention - ai customer retention analysis
- Using Claude for Business Analysis - claude ai business analysis
Want this system built for your business?
Get a free assessment. We will map every system your business needs and show you the ROI.
Get Your Free Assessment