Skip to content

Commit

Permalink
fix(bigquery): adds order_by to window functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mjirv committed Oct 26, 2022
1 parent 522ae82 commit 40bab3c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions macros/funnel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

, event_funnel as (
{% for step in steps %}
select '{{ step }}' as event_type, unique_users
select '{{ step }}' as event_type, unique_users, {{ loop.index }} as step_index
from step_{{ loop.index }}
{% if not loop.last %}
union all
Expand All @@ -36,8 +36,8 @@

, final as (
select event_type
, unique_users, 1.0 * unique_users / nullif(first_value(unique_users) over(), 0) as pct_conversion
, 1.0 * unique_users / nullif(lag(unique_users) over(), 0) as pct_of_previous
, unique_users, 1.0 * unique_users / nullif(first_value(unique_users) over(order by step_index), 0) as pct_conversion
, 1.0 * unique_users / nullif(lag(unique_users) over(order by step_index), 0) as pct_of_previous
from event_funnel
)

Expand Down

0 comments on commit 40bab3c

Please sign in to comment.