Retention Calculation

Customer Retention Rate Calculator & Guide :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –shadow-color: rgba(0, 0, 0, 0.1); –card-background: #fff; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; padding-top: 20px; padding-bottom: 40px; } .container { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 15px; box-sizing: border-box; } header { background-color: var(–primary-color); color: white; padding: 20px 0; text-align: center; width: 100%; margin-bottom: 30px; } header h1 { margin: 0; font-size: 2.5em; font-weight: 700; } main { width: 100%; display: flex; flex-direction: column; align-items: center; } .calculator-section, .article-section { background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); padding: 30px; margin-bottom: 30px; width: 100%; box-sizing: border-box; } .calculator-section h2, .article-section h2 { color: var(–primary-color); text-align: center; margin-top: 0; margin-bottom: 25px; font-size: 2em; } .loan-calc-container { display: flex; flex-direction: column; gap: 20px; } .input-group { display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: 600; color: var(–primary-color); } .input-group input[type="number"], .input-group select { padding: 12px 15px; border: 1px solid var(–border-color); border-radius: 5px; font-size: 1em; box-sizing: border-box; width: 100%; } .input-group input[type="number"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #666; margin-top: 5px; } .error-message { color: #dc3545; font-size: 0.85em; margin-top: 5px; display: none; /* Hidden by default */ } .button-group { display: flex; gap: 15px; margin-top: 25px; justify-content: center; flex-wrap: wrap; } .button-group button { padding: 12px 25px; border: none; border-radius: 5px; font-size: 1em; font-weight: 600; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; white-space: nowrap; } .button-group button.primary { background-color: var(–primary-color); color: white; } .button-group button.primary:hover { background-color: #003366; transform: translateY(-2px); } .button-group button.secondary { background-color: #6c757d; color: white; } .button-group button.secondary:hover { background-color: #5a6268; transform: translateY(-2px); } .button-group button.reset { background-color: #ffc107; color: #212529; } .button-group button.reset:hover { background-color: #e0a800; transform: translateY(-2px); } .results-section { background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); padding: 30px; margin-top: 30px; width: 100%; box-sizing: border-box; text-align: center; } .results-section h3 { color: var(–primary-color); margin-top: 0; font-size: 1.8em; margin-bottom: 20px; } .main-result { font-size: 2.5em; font-weight: 700; color: var(–success-color); background-color: #e9f7ef; padding: 15px 25px; border-radius: 8px; display: inline-block; margin-bottom: 20px; min-width: 150px; } .intermediate-results { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; margin-bottom: 25px; } .intermediate-result-item { background-color: #eef2f7; padding: 15px 20px; border-radius: 5px; text-align: center; flex: 1 1 150px; /* Grow, shrink, basis */ max-width: 200px; } .intermediate-result-item .label { font-size: 0.9em; color: #555; display: block; margin-bottom: 5px; } .intermediate-result-item .value { font-size: 1.5em; font-weight: 600; color: var(–primary-color); } .formula-explanation { font-size: 0.95em; color: #444; margin-top: 15px; padding-top: 15px; border-top: 1px solid var(–border-color); } .chart-container { margin-top: 30px; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); width: 100%; box-sizing: border-box; text-align: center; } .chart-container h3 { color: var(–primary-color); margin-top: 0; font-size: 1.8em; margin-bottom: 20px; } canvas { max-width: 100%; height: auto !important; /* Ensure canvas scales properly */ } .table-container { margin-top: 30px; overflow-x: auto; /* For responsiveness */ } .table-container caption { font-size: 1.1em; font-weight: 600; color: var(–primary-color); margin-bottom: 15px; caption-side: top; text-align: left; } table { width: 100%; border-collapse: collapse; border-radius: 8px; overflow: hidden; /* For rounded corners */ } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(–border-color); } thead th { background-color: var(–primary-color); color: white; font-weight: 600; } tbody tr:nth-child(even) { background-color: #f2f6fa; } tbody tr:hover { background-color: #e0e8f0; } .article-section { text-align: left; } .article-section h2 { text-align: left; font-size: 2.2em; margin-bottom: 20px; } .article-section h3 { font-size: 1.6em; color: var(–primary-color); margin-top: 25px; margin-bottom: 15px; } .article-section p, .article-section ul, .article-section ol { margin-bottom: 20px; font-size: 1.05em; } .article-section ul, .article-section ol { padding-left: 25px; } .article-section li { margin-bottom: 10px; } .article-section strong { color: var(–primary-color); } .faq-section { margin-top: 30px; } .faq-item { margin-bottom: 15px; border-left: 3px solid var(–primary-color); padding-left: 15px; background-color: #fdfdfd; padding-top: 10px; padding-bottom: 10px; border-radius: 0 5px 5px 0; } .faq-item strong { display: block; font-size: 1.1em; color: var(–primary-color); margin-bottom: 5px; } .faq-item p { margin-bottom: 0; font-size: 1em; } .internal-links-section { margin-top: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); padding: 30px; width: 100%; box-sizing: border-box; } .internal-links-section h2 { text-align: left; font-size: 2em; margin-bottom: 20px; } .internal-links-section ul { list-style: none; padding: 0; } .internal-links-section li { margin-bottom: 15px; border-bottom: 1px dashed var(–border-color); padding-bottom: 10px; } .internal-links-section li:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; } .internal-links-section a { color: var(–primary-color); text-decoration: none; font-weight: 600; font-size: 1.1em; } .internal-links-section a:hover { text-decoration: underline; } .internal-links-section p { font-size: 0.95em; color: #555; margin-top: 5px; margin-bottom: 0; } footer { text-align: center; margin-top: 40px; font-size: 0.9em; color: #777; width: 100%; } /* Responsive adjustments */ @media (min-width: 768px) { .button-group { justify-content: flex-start; } }

Customer Retention Rate Calculator

Measure and improve your customer loyalty.

Retention Rate Calculator

Number of customers you had at the beginning of the period.
Number of customers you had at the end of the period.
Number of new customers gained during the period.

Your Retention Metrics

Customers Lost
Retention Rate (%)
Churn Rate (%)
Formula Used:
Retention Rate = ((Customers at End – New Customers) / Customers at Start) * 100
Customers Lost = Customers at Start – (Customers at End – New Customers)
Churn Rate = (Customers Lost / Customers at Start) * 100

Customer Flow Over Time

Key Metrics Summary
Metric Value Description
Customers at Start Initial customer count for the period.
Customers at End Final customer count for the period.
New Customers Customers acquired during the period.
Customers Lost Customers who stopped doing business.
Retention Rate Percentage of customers retained.
Churn Rate Percentage of customers lost.

What is Customer Retention Rate?

Customer retention rate is a critical Key Performance Indicator (KPI) that measures the percentage of customers a business retains over a specific period. It answers the fundamental question: "How many of our existing customers stayed with us?" A high retention rate signifies customer satisfaction, loyalty, and the effectiveness of business strategies in keeping customers engaged. Conversely, a low retention rate can indicate underlying issues with product, service, pricing, or customer experience. Understanding and improving your customer retention rate is often more cost-effective than acquiring new customers, making it a cornerstone of sustainable business growth.

Who should use it? Any business that relies on repeat customers can benefit from tracking their retention rate. This includes subscription services (SaaS, streaming), e-commerce businesses, retail stores, financial institutions, and service providers. Marketing managers, customer success teams, product developers, and executive leadership all use this metric to gauge business health and inform strategic decisions.

Common Misconceptions: One common misconception is that retention rate is the same as customer satisfaction. While related, satisfaction is a feeling, and retention is an action. A customer might be satisfied but still leave for a better offer. Another mistake is confusing retention with revenue growth; you can retain customers but see declining revenue if they spend less. Finally, some businesses focus solely on acquiring new customers, neglecting the vital importance of nurturing their existing base, which is often a more profitable strategy.

Customer Retention Rate Formula and Mathematical Explanation

The customer retention rate calculation is straightforward but requires careful definition of the period and customer counts. The standard formula focuses on the customers who were retained from the beginning of the period, excluding those acquired during the period from the retention calculation itself.

The Core Formula:

The primary formula for calculating the customer retention rate is:

Retention Rate (%) = ((E – N) / S) * 100

Where:

  • E = Number of customers at the End of the period
  • N = Number of New customers acquired during the period
  • S = Number of customers at the Start of the period

The term (E – N) represents the number of customers from the beginning of the period who remained customers until the end. This is crucial because new customers acquired during the period don't contribute to the retention of the *original* customer base.

Calculating Customers Lost (Churn):

To understand retention, it's equally important to understand churn (customer attrition). The number of customers lost can be derived:

Customers Lost = S – (E – N)

Alternatively, if you track churn directly:

Customers Lost = Customers at Start – Customers Remaining at End (from the start cohort)

The churn rate is then calculated as:

Churn Rate (%) = (Customers Lost / S) * 100

A high churn rate directly corresponds to a low retention rate, and vice versa. These two metrics provide a complete picture of customer loyalty dynamics.

Variables Table:

Retention Calculation Variables
Variable Meaning Unit Typical Range
S (Customers at Start) Total number of customers at the beginning of the measurement period. Count 100 – 1,000,000+
E (Customers at End) Total number of customers at the end of the measurement period. Count 100 – 1,000,000+
N (New Customers) Number of customers acquired during the measurement period. Count 0 – 100,000+
Customers Lost Number of customers from the start of the period who are no longer customers at the end. Count 0 – 1,000,000+
Retention Rate Percentage of customers retained from the start of the period. % 0% – 100%+ (can exceed 100% if E is significantly larger than S and N is small, indicating strong growth)
Churn Rate Percentage of customers lost from the start of the period. % 0% – 100%

Practical Examples (Real-World Use Cases)

Example 1: SaaS Subscription Business

"CloudSync," a Software-as-a-Service provider, wants to assess its customer retention for the last quarter (Q3).

  • Customers at Start of Period (S): 500
  • Customers at End of Period (E): 550
  • New Customers Acquired During Period (N): 100

Calculation:

  • Customers Remaining from Start = E – N = 550 – 100 = 450
  • Retention Rate = ((450) / 500) * 100 = 90%
  • Customers Lost = S – (E – N) = 500 – 450 = 50
  • Churn Rate = (50 / 500) * 100 = 10%

Interpretation: CloudSync retained 90% of its customers from the beginning of the quarter. A 10% churn rate might be acceptable depending on the industry, but the company should investigate why 50 customers left. Are there specific features causing frustration, or is onboarding inadequate for new users? This data prompts a review of customer feedback and product usage.

Example 2: E-commerce Retailer

"StyleHub," an online fashion retailer, analyzes its customer retention for the month of July.

  • Customers at Start of Period (S): 2,000
  • Customers at End of Period (E): 2,150
  • New Customers Acquired During Period (N): 300

Calculation:

  • Customers Remaining from Start = E – N = 2,150 – 300 = 1,850
  • Retention Rate = ((1,850) / 2,000) * 100 = 92.5%
  • Customers Lost = S – (E – N) = 2,000 – 1,850 = 150
  • Churn Rate = (150 / 2,000) * 100 = 7.5%

Interpretation: StyleHub achieved a 92.5% retention rate in July. While seemingly good, the company notes that 150 customers were lost. They might investigate if this loss is concentrated among first-time buyers (indicating issues with the initial purchase experience) or repeat customers (suggesting problems with product quality, shipping, or customer service). Understanding the source of churn is key to improving the customer retention rate formula application.

How to Use This Customer Retention Rate Calculator

Our free online calculator simplifies the process of measuring your business's customer loyalty. Follow these steps to get accurate insights:

  1. Define Your Period: Decide on the timeframe you want to analyze. This could be a month, a quarter, or a year. Consistency is key for tracking trends.
  2. Input Starting Customers: Enter the total number of customers you had at the very beginning of your chosen period into the "Customers at Start of Period" field.
  3. Input Ending Customers: Enter the total number of customers you had at the very end of your chosen period into the "Customers at End of Period" field.
  4. Input New Customers: Enter the number of entirely new customers you acquired *during* the period into the "New Customers Acquired During Period" field. This is crucial for accurately calculating retention based on your original customer base.
  5. Click Calculate: Press the "Calculate Retention" button. The calculator will instantly display your primary retention rate, along with key intermediate values like customers lost, churn rate, and the calculated retention percentage.

How to Read Results:

  • Main Result (Retention Rate %): This is your primary metric. A higher percentage indicates better customer loyalty. Aim for industry benchmarks or your own historical improvements.
  • Customers Lost: Shows the absolute number of customers who churned from your starting cohort.
  • Churn Rate (%): The inverse of retention, showing the percentage of customers lost. Lower is generally better.
  • Chart & Table: Visualize the customer flow and review a detailed breakdown of the metrics.

Decision-Making Guidance:

  • High Retention Rate: Congratulations! Analyze what's working well. Can you replicate these successes? Consider focusing on increasing customer lifetime value (CLV) through upselling or cross-selling. Explore customer lifetime value calculators.
  • Low Retention Rate: This signals a need for action. Investigate the reasons for churn. Is it product-market fit, customer service issues, competitive pressure, or pricing? Implement strategies to improve customer experience, loyalty programs, or onboarding processes.
  • Compare Over Time: Use the calculator regularly to track changes. Are your retention efforts paying off? Identify trends and adjust your strategies accordingly.

Key Factors That Affect Retention Rate Results

Several interconnected factors influence how well a business retains its customers. Understanding these can help diagnose retention issues and inform strategic improvements:

  1. Product/Service Quality & Value: The core offering must consistently meet or exceed customer expectations. If the product is buggy, unreliable, or doesn't deliver the promised value, customers will leave. This is fundamental to achieving high customer retention rate.
  2. Customer Service & Support: Responsive, empathetic, and effective customer support is crucial. Poor service experiences are a major driver of churn. Quick resolution of issues and proactive support can significantly boost loyalty.
  3. Onboarding Experience: For subscription services or complex products, a smooth and informative onboarding process helps customers understand the value proposition quickly. A confusing or difficult onboarding can lead to early churn.
  4. Pricing & Perceived Value: Customers constantly evaluate if the price they pay aligns with the value they receive. Competitively priced offerings and clear value communication are essential. Frequent price increases without corresponding value additions can alienate customers.
  5. Customer Engagement & Communication: Regularly engaging customers through relevant content, personalized offers, and updates keeps your brand top-of-mind. Lack of engagement can lead to customers forgetting your brand or finding alternatives.
  6. Loyalty Programs & Incentives: Rewarding repeat business through loyalty programs, exclusive discounts, or early access to new features can incentivize customers to stay. These programs directly impact the retention calculation by fostering repeat purchases.
  7. Competitive Landscape: The availability and attractiveness of competitor offerings significantly impact retention. If competitors offer superior features, better pricing, or a more compelling user experience, customers may be tempted to switch.
  8. Market Changes & Economic Factors: Broader economic downturns, shifts in consumer preferences, or disruptive technological advancements can influence customer spending habits and loyalty, indirectly affecting retention rates.

Frequently Asked Questions (FAQ)

Q: What is a "good" customer retention rate?

A: A "good" retention rate varies significantly by industry. For example, subscription businesses might aim for 80-90%+, while industries with lower switching costs or more frequent purchase cycles might have lower acceptable rates. It's best to benchmark against industry averages and focus on improving your own historical performance.

Q: Why is retention more important than acquisition?

Acquiring a new customer can cost 5 to 25 times more than retaining an existing one. Retained customers tend to spend more over time and act as brand advocates, providing valuable word-of-mouth marketing. Focusing on retention builds a more stable and profitable revenue stream.

Q: How often should I calculate my retention rate?

It's recommended to calculate your retention rate monthly or quarterly. Monthly tracking allows for quicker identification of issues and faster response times. Quarterly tracking provides a broader view and helps identify seasonal trends.

Q: Can my retention rate be over 100%?

Yes, technically. If the number of customers at the end of the period (E), minus new customers (N), is greater than the number of customers at the start (S), your retention rate will exceed 100%. This indicates significant growth where new customer acquisition outpaced the loss of existing customers. However, the core retention calculation focuses on the *original* cohort's survival.

Q: What's the difference between retention rate and churn rate?

They are two sides of the same coin. Retention rate measures the percentage of customers you *keep*, while churn rate measures the percentage of customers you *lose*. If your retention rate is 90%, your churn rate is 10%.

Q: Does revenue retention matter?

Absolutely. Revenue retention (or Net Revenue Retention – NRR) measures the percentage of recurring revenue retained from existing customers, accounting for upgrades, downgrades, and churn. It's a vital metric, especially for subscription businesses, as it shows if your existing customer base is growing in value.

Q: How do I calculate retention for a business with fluctuating customer numbers (e.g., daily users)?

For businesses with very high transaction volumes or daily active users, a simple count might be less effective. You might need to adapt the calculation, perhaps by focusing on cohorts (groups of users who signed up at the same time) or using average daily/monthly active users over the period, adjusting the formula accordingly.

Q: What if I don't track new customers separately?

If you only have the start and end customer counts, you can calculate a gross retention rate: (Customers at End / Customers at Start) * 100. However, this doesn't distinguish between retaining old customers and acquiring new ones. For accurate insights into loyalty, tracking new customers separately is essential for the standard retention calculation formula.

© 2023 Your Company Name. All rights reserved.

var chartInstance = null; // Global variable to hold chart instance function validateInput(id, min, max) { var input = document.getElementById(id); var errorElement = document.getElementById('error_' + id); var value = parseFloat(input.value); errorElement.style.display = 'none'; // Hide previous error if (isNaN(value)) { errorElement.textContent = 'Please enter a valid number.'; errorElement.style.display = 'block'; return false; } if (value max) { errorElement.textContent = 'Value cannot exceed ' + max + '.'; errorElement.style.display = 'block'; return false; } return true; } function calculateRetention() { var valid = true; valid = validateInput('customers_start_period', 0) && valid; valid = validateInput('customers_end_period', 0) && valid; valid = validateInput('new_customers', 0) && valid; if (!valid) { return; } var customersStart = parseFloat(document.getElementById('customers_start_period').value); var customersEnd = parseFloat(document.getElementById('customers_end_period').value); var newCustomers = parseFloat(document.getElementById('new_customers').value); var customersRemainingFromStart = customersEnd – newCustomers; var customersLost = customersStart – customersRemainingFromStart; var retentionRate = 0; var churnRate = 0; if (customersStart > 0) { retentionRate = (customersRemainingFromStart / customersStart) * 100; churnRate = (customersLost / customersStart) * 100; } else { // Handle division by zero if starting customers is 0 retentionRate = 0; churnRate = 0; if (customersEnd > 0) { // If start is 0 and end is > 0, it implies infinite retention conceptually, // but practically, we can't calculate a rate based on zero. // We'll show 0% churn and 100% retention if end > 0, or handle as special case. // For simplicity, let's cap retention at 100% if start is 0 and end > 0. if (customersEnd > newCustomers) { retentionRate = 100; // Or indicate "N/A" or similar } } } // Ensure rates are not negative due to potential input errors or edge cases retentionRate = Math.max(0, retentionRate); churnRate = Math.max(0, churnRate); // Display main result var mainResultElement = document.getElementById('main-result'); mainResultElement.textContent = retentionRate.toFixed(2) + '%'; // Display intermediate results document.getElementById('customers_lost_val').textContent = customersLost.toFixed(0); document.getElementById('retention_rate_val').textContent = retentionRate.toFixed(2); document.getElementById('churn_rate_val').textContent = churnRate.toFixed(2); // Update table document.getElementById('table_start_customers').textContent = customersStart.toFixed(0); document.getElementById('table_end_customers').textContent = customersEnd.toFixed(0); document.getElementById('table_new_customers').textContent = newCustomers.toFixed(0); document.getElementById('table_customers_lost').textContent = customersLost.toFixed(0); document.getElementById('table_retention_rate').textContent = retentionRate.toFixed(2) + '%'; document.getElementById('table_churn_rate').textContent = churnRate.toFixed(2) + '%'; // Update chart updateChart(customersStart, customersEnd, newCustomers, customersLost); } function updateChart(start, end, newCust, lostCust) { var ctx = document.getElementById('retentionChart').getContext('2d'); // Destroy previous chart instance if it exists if (chartInstance) { chartInstance.destroy(); } // Prepare data for the chart // We'll show: // 1. Starting Customers // 2. Customers Remaining from Start (End – New) // 3. New Customers Acquired // 4. Customers Lost (can be inferred or shown explicitly) var labels = ['Start', 'End']; var datasets = [ { label: 'Customers at Start', data: [start, null], // Only show at the start point backgroundColor: 'rgba(0, 74, 153, 0.6)', borderColor: 'rgba(0, 74, 153, 1)', borderWidth: 1, fill: false, pointRadius: 5, pointHoverRadius: 7 }, { label: 'Customers Remaining (from Start)', data: [null, end – newCust], // Show at the end point backgroundColor: 'rgba(40, 167, 69, 0.6)', borderColor: 'rgba(40, 167, 69, 1)', borderWidth: 1, fill: false, pointRadius: 5, pointHoverRadius: 7 }, { label: 'New Customers Acquired', data: [null, newCust], // Show added at the end point backgroundColor: 'rgba(255, 193, 7, 0.6)', borderColor: 'rgba(255, 193, 7, 1)', borderWidth: 1, fill: false, pointRadius: 5, pointHoverRadius: 7 }, { label: 'Customers Lost', data: [null, lostCust], // Show as a reduction at the end point backgroundColor: 'rgba(220, 53, 69, 0.6)', borderColor: 'rgba(220, 53, 69, 1)', borderWidth: 1, fill: false, pointRadius: 5, pointHoverRadius: 7 } ]; // Adjust data points for clarity: // Show start count at 'Start' // Show end count at 'End' // Show new customers added at 'End' // Show lost customers at 'End' var chartData = { labels: ['Start of Period', 'End of Period'], datasets: [ { label: 'Total Customers', data: [start, end], borderColor: 'var(–primary-color)', backgroundColor: 'rgba(0, 74, 153, 0.2)', fill: false, tension: 0.1, pointRadius: 6, pointHoverRadius: 8 }, { label: 'Customers Retained (from Start Cohort)', data: [null, end – newCust], // Only show at end borderColor: 'var(–success-color)', backgroundColor: 'rgba(40, 167, 69, 0.2)', fill: false, tension: 0.1, pointRadius: 6, pointHoverRadius: 8 }, { label: 'New Customers Acquired', data: [null, newCust], // Only show at end borderColor: 'orange', backgroundColor: 'rgba(255, 165, 0, 0.2)', fill: false, tension: 0.1, pointRadius: 6, pointHoverRadius: 8 } ] }; chartInstance = new Chart(ctx, { type: 'line', data: chartData, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, title: { display: true, text: 'Number of Customers' } } }, plugins: { title: { display: true, text: 'Customer Flow Analysis' }, tooltip: { mode: 'index', intersect: false, } }, hover: { mode: 'nearest', intersect: true } } }); } function resetCalculator() { document.getElementById('customers_start_period').value = '1000'; document.getElementById('customers_end_period').value = '1100'; document.getElementById('new_customers').value = '200'; // Clear errors var errorElements = document.querySelectorAll('.error-message'); for (var i = 0; i < errorElements.length; i++) { errorElements[i].style.display = 'none'; errorElements[i].textContent = ''; } calculateRetention(); // Recalculate with default values } function copyResults() { var mainResult = document.getElementById('main-result').textContent; var customersLost = document.getElementById('customers_lost_val').textContent; var retentionRate = document.getElementById('retention_rate_val').textContent; var churnRate = document.getElementById('churn_rate_val').textContent; var startCustomers = document.getElementById('customers_start_period').value; var endCustomers = document.getElementById('customers_end_period').value; var newCustomers = document.getElementById('new_customers').value; var resultsText = "— Retention Rate Calculation Results —\n\n"; resultsText += "Key Assumptions:\n"; resultsText += "- Customers at Start: " + startCustomers + "\n"; resultsText += "- Customers at End: " + endCustomers + "\n"; resultsText += "- New Customers Acquired: " + newCustomers + "\n\n"; resultsText += "Calculated Metrics:\n"; resultsText += "- Retention Rate: " + retentionRate + "%\n"; resultsText += "- Customers Lost: " + customersLost + "\n"; resultsText += "- Churn Rate: " + churnRate + "%\n\n"; resultsText += "Main Result:\n"; resultsText += "- Retention Rate: " + mainResult + "\n"; // Use a temporary textarea to copy text var textArea = document.createElement("textarea"); textArea.value = resultsText; textArea.style.position = "fixed"; // Avoid scrolling to bottom textArea.style.left = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'Results copied to clipboard!' : 'Copying failed!'; // Optionally show a temporary message to the user console.log(msg); } catch (err) { console.log('Unable to copy results', err); } document.body.removeChild(textArea); } // Initial calculation on page load window.onload = function() { // Ensure Chart.js is loaded before trying to use it if (typeof Chart !== 'undefined') { calculateRetention(); } else { // Fallback or error message if Chart.js is not loaded console.error("Chart.js library not found. Chart will not be displayed."); // Optionally, hide the chart container or show a message document.querySelector('.chart-container').style.display = 'none'; } };

Leave a Comment