Explore this snippet with some demo data here.
When a quantity is increasing in time by the same fraction every period, it is said to exhibit compound growth - every time period it increases by a larger amount. It is possible to show that the behaviour of the quantity over time follows the law
x(t) = x(0) * exp(r * t)
where
x(t)
is the value of the quantity nowx(0)
is the value of the quantity at time t = 0t
is time in units of [time_period]r
is the growth rate in units of 1 / [time_period]
From the equation above, to calculate a growth rate you need to know:
- The value at the start of a period
- The value at the end of a period
- The duration of the period
Then, following some algebra, the growth rate is given by
r = ln(x(t) / x(0)) / t
For a concrete example, assume a table with columns:
num_this_month
- this isx(t)
num_last_month
- this isx(0)
In the following then, growth_rate
is the equivalent yearly growth rate for that month:
-- with_growth_rate
select
*,
log(num_this_month / num_last_month) * 12 growth_rate
from with_previous_month
To better depict the effects of a given growth rate, it can be converted to a year-on-year growth factor by inserting into the exponential formula above with t = 1 (one year duration). Or mathematically,
yoy_growth = x(1) / x(0) = exp(r)
It is always sensible to spot-check what a growth rate actually represents to decide whether or not it is a useful metric.
-- with_yoy_growth
select
*,
exp(growth_rate) as yoy_growth
from with_growth_rate