Courseiva

PDE Preparing and Using Data for Analysis Practice Question

You have a BigQuery table 'events' with a TIMESTAMP column 'event_time'. You need to compute, for each event, the difference in seconds from the previous event of the same user. Which window function should you use?

⚠ Common exam trap

Candidates often confuse LAG with LEAD — candidates often pick LEAD because they think 'previous' maps to the next row, but LAG looks backward and LEAD looks forward.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

LAG(event_time) OVER (PARTITION BY user_id ORDER BY event_time)

LAG(event_time) OVER (PARTITION BY user_id ORDER BY event_time) returns the event_time value from the previous row within the same user_id partition, ordered chronologically. Subtracting that returned timestamp from the current row's event_time (e.g., TIMESTAMP_DIFF(event_time, LAG(...), SECOND)) yields the seconds elapsed since the user's prior event. This is the canonical pattern for gap/delta calculations in BigQuery analytic functions.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    FIRST_VALUE(event_time) OVER (PARTITION BY user_id ORDER BY event_time)

    Why it's wrong here

    FIRST_VALUE returns the partition's earliest event_time for every row, so each difference is measured against the user's first event, not the immediately preceding one. It is tempting for baselines, but LAG gives the prior row's timestamp.

  • ✗

    LEAD(event_time) OVER (PARTITION BY user_id ORDER BY event_time)

    Why it's wrong here

    LEAD returns the following row's event_time, giving the gap to the next event rather than the previous one. It is tempting because it is the mirror of the required function, but the stem asks for the difference from the preceding event.

  • ✓

    LAG(event_time) OVER (PARTITION BY user_id ORDER BY event_time)

    Why this is correct

    LAG(event_time) OVER (PARTITION BY user_id ORDER BY event_time) retrieves the preceding row's timestamp within each user's partition, satisfying the per-user sequential comparison the stem requires. Subtracting it from the current event_time yields the seconds elapsed since that user's previous event, without collapsing rows as aggregation would.

  • ✗

    ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY event_time)

    Why it's wrong here

    ROW_NUMBER assigns a sequential position per partition; it returns an integer rank, not a timestamp, so no interval can be computed from it. It is tempting for ordering events, but LAG supplies the previous row's value needed for the subtraction.

About these practice questions

One of 747 original PDE practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Google Cloud exam blueprint

This PDE practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PDE exam.