SQL LEAD

The mirror image of LAG — reach forward to the next row's value instead of back.

What & Why

LEAD(column) pulls a value from the row immediately after the current one. Same mechanics as LAG, opposite direction.

See How It Works

BUSINESS QUESTION

Show each daily active-user value beside the next day and calculate the change that follows.

date_daydaunew_usersreturning_users
2024-04-0112401801060
2024-04-0213152051110
2024-04-0312881641124
2024-04-0413922211171
Watch LEAD read the next DAU rowStep 1 of 4
LEAD(dau) OVER (ORDER BY date_day)
date_daydaunext_dauchange_to_next
2024-04-0112401315+75
2024-04-0213151288-27
2024-04-0312881392+104
2024-04-041392NULLNULL

April 1 looks forward to 1315.

EXAMPLE QUERY
SELECT
  date_day,
  dau,
  LEAD(dau) OVER (ORDER BY date_day) AS next_dau,
  LEAD(dau) OVER (ORDER BY date_day) - dau AS change_to_next
FROM growth.daily_active_users
ORDER BY date_day;

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario