Problems / First-Touch Attribution / Editorial
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY touch_time)
rn = 1
MIN(touch_time)
SUM(amount) GROUP BY user_id
COUNT(*)
SUM
DESC
Attribution problems decompose into one fact per entity decisions: each customer needs exactly one channel (arg-min via ROW_NUMBER) and exactly one revenue number (pre-aggregation). Both CTEs exist to enforce that one-row-per-user invariant before the final join — collapse first, join after, and the per-channel rollup becomes trivially correct. Skip either collapse and the join grain silently multiplies revenue.
Solve First-Touch Attribution yourself →