From 40bab3c11f37a7784c1bfad80179c3eb7d4f985c Mon Sep 17 00:00:00 2001 From: Michael Irvine Date: Tue, 25 Oct 2022 22:33:23 -0400 Subject: [PATCH] fix(bigquery): adds order_by to window functions --- macros/funnel.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/macros/funnel.sql b/macros/funnel.sql index 752276e..4dd5676 100644 --- a/macros/funnel.sql +++ b/macros/funnel.sql @@ -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 @@ -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 )