This function, `toAnnual`, calculates the equivalent **annual churn rate** based...
June 27, 2025 at 08:44 PM
This function, toAnnual
, calculates the equivalent annual churn rate based on a given monthly churn rate. Here's a breakdown of how it works:
-
Input Normalization:
- If the input
monthlyChurn
is greater than 1, the function assumes it is expressed as a percentage (e.g.,10
for 10%) rather than a decimal (e.g.,0.1
for 10%). - It divides the input by
100
to convert it into a decimal format.
- If the input
-
Input Validation:
- If the
monthlyChurn
is outside the valid range (less than 0 or greater than or equal to1
), it returns an error message:"Invalid input: must be between 0% and less than 100%"
. - This ensures the function only deals with valid churn rates.
- If the
-
Churn Rate Conversion:
- The formula
1 - (1 - monthlyChurn)^12
is used to compute the annual churn rate. - It is based on the compounding effect where the annual churn rate is not a simple multiplication of the monthly churn rate but rather reflects cumulative loss over a 12-month period.
- The formula
-
Output:
- The computed
annualChurn
is returned as a decimal value. - Optionally, the caller could interpret it as a percentage by further converting it, though the function itself does not explicitly format it as a percentage.
- The computed
Example Usage:
toAnnual(0.1); // Input 10% (or 0.1 as decimal). Output will be approximately 0.713 (71.3% annual churn).
toAnnual(10); // Input 10% as number, normalized first, output will be the same as above (71.3%).
toAnnual(-0.2); // Invalid input, returns an error message.
toAnnual(1); // Invalid input, returns an error message.
The function is a custom function designed for scenarios such as analytics dashboards (e.g., in spreadsheets or SaaS applications) to help users understand retention and churn trends.
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node