Here’s the precise analytic recipe you can drop straight into your SkyWell workspace once the Opportunity and Task tables are registered correctly. It will:
1. Compute each deal’s most recent activity date by joining your Task history (`activity_date`) to each Opportunity (`id`).
2. Filter to “stalled” deals—those still open whose last activity was more than N days ago.
3. Follow those same deals forward to their ultimate outcome (Closed Won vs. Closed Lost) and compute the win/loss percentages.
```sql
-- Replace :N with your inactivity threshold in days
WITH last_activity AS (
SELECT
so.id AS deal_id,
so.name AS deal_name,
so.stage AS current_stage,
MAX(st.activity_date) AS last_activity_date
FROM opportunities so
LEFT JOIN tasks st
ON st.what_id = so.id
GROUP BY so.id, so.name, so.stage
),
stalled_open AS (
SELECT
deal_id,
deal_name,
current_stage,
last_activity_date
FROM last_activity
WHERE current_stage NOT IN ('Closed Won','Closed Lost')
AND (julianday('now') - julianday(COALESCE(last_activity_date,'1900-01-01'))) > :N
),
outcomes AS (
SELECT
so.id AS deal_id,
so.stage AS final_stage
FROM opportunities so
WHERE so.id IN (SELECT deal_id FROM stalled_open)
AND so.stage IN ('Closed Won','Closed Lost')
)
SELECT
COUNT(*) AS total_stalled,
SUM(final_stage='Closed Won') AS closed_won_count,
SUM(final_stage='Closed Lost') AS closed_lost_count,
ROUND(100.0*SUM(final_stage='Closed Won')/COUNT(*),2) AS pct_closed_won,
ROUND(100.0*SUM(final_stage='Closed Lost')/COUNT(*),2) AS pct_closed_lost
FROM outcomes;
```
– “total_stalled” gives you how many deals went stale.
– “pct_closed_won” vs. “pct_closed_lost” shows what share of those stalled deals ultimately won versus dropped out.
Once you confirm that `opportunities` and `tasks` are available to SkyWell under those names, running this will yield the exact percentages you’re looking for.