Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Error encountered while calculating median using percentile_cont function › Reply To: Error encountered while calculating median using percentile_cont function
-
The function
percentile_contrequires a float value, not a table. In your query, you need to usex.colto refer to the columncolin your tablex. Here’s how you can adjust your code:With your ‘masterdata’ table data source,
the code ‘Select 10000*rand() as user_eng_time from unnest (generate_array(1,100))‘ generates data for masterdata.Then,
the query selects everything and calculates the percentile using
‘percentile_cont(x.col,0.5) over () as median_time_in_seconds‘.And this selection is made within a subquery that selects and rounds ‘user_eng_time’ divided by 1000,
as named by column ‘col’ from the masterdata table:
‘select round(user_eng_time/1000) as col from masterdata‘.This subquery is represented as table ‘x’ in the main query.