SQL Percentage Change

How much a value grew or shrank relative to where it started — (new - old) / old * 100. The sign tells you the direction.

What & Why

Percentage change measures relative movement between two values: (new_value - old_value) / old_value * 100. A positive result means growth; a negative result means decline. This needs LAG (a window function from the Advanced tier) in a real query to access "last month's" value alongside the current row — this lesson focuses on the formula itself.

See How It Works

BUSINESS QUESTION

Growth wants the day-over-day percentage change in daily active users.

date_daydaunew_usersreturning_users
2024-04-0112401801060
2024-04-0213152051110
2024-04-0312881641124
2024-04-0413922211171
Watch change use the previous value as its baselineExample 1 of 4
(current - previous) / previous × 100
date_daydauprevious_dauchange_pct
2024-04-011240NULLNULL
2024-04-021315??
2024-04-031288??
2024-04-041392??

The first ordered day has no previous DAU value.

EXAMPLE QUERY
WITH compared AS (
  SELECT
    date_day,
    dau,
    LAG(dau) OVER (ORDER BY date_day) AS previous_dau
  FROM growth.daily_active_users
)
SELECT
  date_day,
  dau,
  previous_dau,
  ROUND((dau - previous_dau)::numeric / NULLIF(previous_dau, 0) * 100, 2) AS change_pct
FROM compared
ORDER BY date_day;
Now You Try

Practice this concept

Growth wants the day-over-day percentage change in daily active users.

Available schema
growth

Prefix tables with growth.table_name.

date_daydauprevious_dauchange_pct
growth.daily_active_users
ColumnType
date_daydate
dauinteger
new_usersinteger
returning_usersinteger
internal_tracking_codetext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario