Marketing, sales and HR analytics in practice
Apply analytics to customer segmentation, sales productivity and the workforce — attrition, performance, recruitment and productivity — responsibly.
This lesson builds on: Leads, campaigns, cross-sell/upsell and market basket analysis.
- Segment customers with rule-based and data-driven approaches
- Measure sales productivity and employee performance fairly
- Compute headcount, attrition and recruitment funnel metrics correctly
- Handle people data ethically and legally
Customer segmentation
| Approach | Example | Strength |
|---|---|---|
| Demographic / firmographic | Age band, city, company size | Simple, explainable |
| Behavioural | RFM, channel preference, category mix | Predicts behaviour |
| Value-based | CLV tiers | Aligns spend with value |
| Needs-based | Survey-derived | Informs product design |
| Data-driven clustering | k-means on behaviour features | Finds non-obvious groups — must still be explainable and actionable |
Good segments are measurable, sizeable, reachable, distinct and actionable.
Sales performance and productivity
Rep productivity = output ÷ input (revenue per rep, deals per 100 calls, revenue per hour). Compare like with like — territory potential, tenure and lead quality differ. Attainment vs plan corrects partly for territory size, if plans are fair.
SELECT e.job_level,
COUNT(DISTINCT sp.employee_id) AS reps,
ROUND(AVG(sp.sales_actual / sp.sales_plan) * 100, 1) AS avg_attainment_pct,
ROUND(1.0 * SUM(sp.deals_closed) / SUM(sp.calls_made) * 100, 1) AS deals_per_100_calls
FROM sales_performance sp JOIN employees e ON e.employee_id = sp.employee_id
WHERE sp.year_month LIKE '2025%'
GROUP BY e.job_level ORDER BY avg_attainment_pct DESC;| job_level | reps | avg_attainment_pct | deals_per_100_calls |
|---|---|---|---|
| Senior | 17 | 110.2 | 25.7 |
| Mid | 19 | 109.3 | 24.1 |
| Lead | 15 | 107.9 | 25 |
| Manager | 9 | 107.8 | 24.9 |
| Junior | 34 | 106.6 | 24 |
HR analytics: workforce and attrition
| Metric | Formula |
|---|---|
| Headcount (point in time) | Employees employed on a date |
| Average headcount | (start + end) ÷ 2, or average of monthly headcounts |
| Attrition rate (annual) | Leavers in year ÷ average headcount in year |
| Voluntary attrition | Resignations ÷ average headcount |
| Early attrition | Leavers within 12 months of hire ÷ hires |
| Time to fill | Requisition opened → offer accepted (days) |
| Offer acceptance | Offers accepted ÷ offers made |
WITH hc AS (
SELECT
SUM(hire_date <= '2025-01-01' AND (exit_date IS NULL OR exit_date > '2025-01-01')) AS start_hc,
SUM(hire_date <= '2025-12-31' AND (exit_date IS NULL OR exit_date > '2025-12-31')) AS end_hc,
SUM(exit_date BETWEEN '2025-01-01' AND '2025-12-31') AS leavers_2025
FROM employees)
SELECT start_hc, end_hc, leavers_2025,
ROUND(100.0 * leavers_2025 / ((start_hc + end_hc) / 2.0), 1) AS attrition_pct
FROM hc;| start_hc | end_hc | leavers_2025 | attrition_pct |
|---|---|---|---|
| 380 | 337 | 79 | 22 |
Drivers by department:
SELECT d.department_name,
SUM(e.exit_date BETWEEN '2024-01-01' AND '2025-12-31') AS leavers_24_25,
COUNT(*) AS ever_employed,
ROUND(AVG(CASE WHEN e.exit_date IS NOT NULL THEN e.last_rating END), 2) AS avg_rating_leavers,
ROUND(AVG(CASE WHEN e.exit_date IS NULL THEN e.last_rating END), 2) AS avg_rating_stayers
FROM employees e JOIN departments d ON d.department_id = e.department_id
GROUP BY d.department_name ORDER BY leavers_24_25 DESC;| department_name | leavers_24_25 | ever_employed | avg_rating_leavers | avg_rating_stayers |
|---|---|---|---|---|
| Sales | 44 | 174 | 3.07 | 3.29 |
| Customer Service | 42 | 159 | 3.06 | 3.4 |
| Operations | 24 | 130 | 3.26 | 3.36 |
| IT | 13 | 65 | 3.07 | 3.24 |
| Marketing | 9 | 50 | 3.11 | 3.32 |
| Data & Analytics | 8 | 31 | 3.06 | 3.54 |
| Finance | 7 | 43 | 2.95 | 3.17 |
| HR | 4 | 26 | 3.5 | 3.5 |
Interpretation. High-volume departments (Sales, Customer Service) lose the most people; leavers have lower average ratings — consistent with both voluntary exits of disengaged staff and dismissals. Separate voluntary from involuntary before concluding.
Employee performance analytics
Ratings are subjective and manager-dependent; compare distributions across managers (calibration), combine with objective outcomes where they exist (sales attainment), and beware of using one metric to rank people with different roles.
Recruitment metrics
SELECT source, COUNT(*) AS candidates,
SUM(furthest_stage = 'hired') AS hired,
ROUND(100.0 * AVG(furthest_stage = 'hired'), 1) AS hire_rate_pct
FROM recruitment GROUP BY source ORDER BY hire_rate_pct DESC;| source | candidates | hired | hire_rate_pct |
|---|---|---|---|
| career_site | 886 | 48 | 5.4 |
| 856 | 43 | 5 | |
| job_board | 857 | 39 | 4.6 |
| referral | 895 | 38 | 4.2 |
| agency | 916 | 33 | 3.6 |
Ethics and privacy in people analytics
- Use aggregates; suppress groups smaller than ~5 people so individuals cannot be identified.
- Restrict access to HR data; log access.
- Don't build models that decide about individuals (e.g. "flight risk" scores) without legal review, transparency and human oversight; check for bias across protected characteristics.
- Use data only for the purpose it was collected for.
Practice
Headcount was 380 on 1 January and 337 on 31 December; 79 people left during the year. Annual attrition rate in % (1 decimal), using average headcount?
A dashboard shows average salary for a team of 3 people. What is the main concern?
Rep A closes 30k/month in a territory with 2× the potential of Rep B's, who closes 22k. Which statement is fair?
Summary
- Segments must be measurable, distinct and actionable.
- Productivity comparisons need like-for-like context.
- Attrition = leavers ÷ average headcount; separate voluntary/involuntary; analyse drivers carefully.
- People analytics demands aggregation, access control and fairness checks.