function calculateGrowth() {
var previous = parseFloat(document.getElementById('prevValue').value);
var current = parseFloat(document.getElementById('currValue').value);
var resultBox = document.getElementById('resultBox');
var resultDisplay = document.getElementById('growthResult');
var description = document.getElementById('descriptionText');
if (isNaN(previous) || isNaN(current)) {
alert("Please enter valid numerical values for both fields.");
return;
}
if (previous === 0) {
alert("Previous value cannot be zero as it results in an undefined growth rate.");
return;
}
var growthRate = ((current – previous) / previous) * 100;
var formattedGrowth = growthRate.toFixed(2);
resultBox.style.display = "block";
resultDisplay.innerHTML = formattedGrowth + "%";
if (growthRate > 0) {
resultDisplay.className = "yoy-calc-result-value yoy-positive";
description.innerHTML = "Your value increased by " + formattedGrowth + "% compared to the previous period.";
} else if (growthRate < 0) {
resultDisplay.className = "yoy-calc-result-value yoy-negative";
description.innerHTML = "Your value decreased by " + Math.abs(formattedGrowth) + "% compared to the previous period.";
} else {
resultDisplay.className = "yoy-calc-result-value";
description.innerHTML = "There was no change in value over this period.";
}
}
Understanding Year-over-Year (YoY) Growth
Year-over-Year (YoY) growth is a key performance indicator used to compare a financial or data metric from one period to the corresponding period in the previous year. Unlike monthly growth, YoY smoothing out seasonal fluctuations, making it one of the most reliable ways to measure long-term performance.
The YoY Growth Formula
The mathematical calculation for YoY growth is straightforward:
Business Revenue: If your company earned $100,000 in 2022 and $125,000 in 2023, your YoY growth is 25%.
Website Traffic: If your blog had 10,000 visitors in October last year and 15,000 visitors this October, you have achieved a 50% YoY increase in traffic.
Investment Portfolios: An investor can track the value of their assets every December to see the annual percentage gain or loss.
Why Use YoY Instead of MoM?
While Month-over-Month (MoM) growth is useful for short-term tracking, it often suffers from "noise." For example, a retail store might see a 300% MoM increase in December due to holiday shopping, which doesn't necessarily mean the business is inherently growing. By comparing December this year to December last year (YoY), you get a clearer picture of whether the business is actually improving relative to its own history.