function calculateRetention() {
// Get input elements by ID
var startInput = document.getElementById('customersStart');
var endInput = document.getElementById('customersEnd');
var newInput = document.getElementById('customersNew');
var resultBox = document.getElementById('resultBox');
var retentionDisplay = document.getElementById('retentionResult');
var churnDisplay = document.getElementById('churnResult');
var summaryDisplay = document.getElementById('summaryText');
var errorDisplay = document.getElementById('errorMsg');
// Parse values
var S = parseFloat(startInput.value);
var E = parseFloat(endInput.value);
var N = parseFloat(newInput.value);
// Reset error state
errorDisplay.style.display = 'none';
resultBox.style.display = 'none';
// Validation logic
if (isNaN(S) || isNaN(E) || isNaN(N)) {
errorDisplay.innerText = "Please fill in all fields with valid numbers.";
errorDisplay.style.display = 'block';
return;
}
if (S <= 0) {
errorDisplay.innerText = "Customers at start (S) must be greater than zero.";
errorDisplay.style.display = 'block';
return;
}
if (N < 0 || E < 0) {
errorDisplay.innerText = "Customer counts cannot be negative.";
errorDisplay.style.display = 'block';
return;
}
// Logical validation: You cannot acquire more new customers than the total end count (implies negative existing customers)
// However, standard formula allows calculation, but we should warn if E < N
if (E < N) {
errorDisplay.innerText = "Error: End count (E) cannot be less than New customers (N).";
errorDisplay.style.display = 'block';
return;
}
// Calculation Logic
// Formula: ((E – N) / S) * 100
var retainedCustomers = E – N;
var retentionRate = (retainedCustomers / S) * 100;
// Churn Logic: 100 – Retention Rate
var churnRate = 100 – retentionRate;
// Display Results
retentionDisplay.innerHTML = retentionRate.toFixed(2) + "%";
churnDisplay.innerHTML = "Churn Rate: " + churnRate.toFixed(2) + "%";
summaryDisplay.innerHTML = "Out of " + S + " original customers, you retained " + retainedCustomers + " (excluding the " + N + " new acquisitions).";
resultBox.style.display = 'block';
}
How Retention Rate Is Calculated
Customer Retention Rate (CRR) is a critical metric that measures the percentage of customers a company retains over a specific period. Unlike simple customer counts, CRR specifically looks at how well a business keeps its existing clients, excluding any new growth achieved during the same timeframe.
Calculating retention rate provides insight into customer loyalty, product-market fit, and the effectiveness of customer service teams. A high retention rate generally implies a healthy business model, while a low retention rate indicates a leaky bucket problem where customers are leaving as fast as they arrive.
The Retention Rate Formula
To calculate retention rate accurately, you need three distinct data points for a specific period (e.g., a month, quarter, or year):
Retention Rate = [ ( E – N ) / S ] × 100
S (Start): The number of customers at the start of the period.
E (End): The number of customers at the end of the period.
N (New): The number of new customers acquired during the period.
Step-by-Step Calculation Example
Let's say you run a subscription software business and want to calculate your retention rate for the first quarter (Q1).
Determine Start Count (S): On January 1st, you had 200 active subscribers.
Determine End Count (E): On March 31st, you had 220 active subscribers.
Identify New Growth (N): During Q1, you acquired 40 new subscribers.
Using the formula:
((220 – 40) / 200) × 100
First, subtract new customers from the end total: 220 – 40 = 180. This means 180 of the original 200 customers remained.
Next, divide by the starting count: 180 / 200 = 0.9.
Finally, multiply by 100 to get the percentage: 90% Retention Rate.
Why We Subtract New Customers (N)
The most common mistake in calculating retention is simply comparing the Start and End numbers. If you started with 100 customers and ended with 110, it might look like 110% retention. However, if you lost 50 old customers and gained 60 new ones, your actual retention of the original base is poor (50%).
By subtracting N (New Customers), we isolate the original cohort to see exactly how many of them stuck around, providing a true measure of loyalty.
Interpreting the Result
Benchmarks vary significantly by industry. For SaaS (Software as a Service) companies, a retention rate above 35% is often considered acceptable for SMBs, while enterprise contracts often target 90%+. In e-commerce, retention rates are typically lower due to the transactional nature of the business.
The inverse of your retention rate is your Churn Rate. If your retention rate is 90%, your churn rate is 10%.