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

  • Logan

    Member
    22 June 2023 at 4:28 am

    The function percentile_cont requires a float value, not a table. In your query, you need to use x.col to refer to the column col in your table x. 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.