outliers_percentiles - BigQuery

Function

outliers_percentiles(col, value_percentile_5, value_percentile_95)

Description

Outliers Percentiles - Detects if a <value> is an outlier based on then 5th percentile <value_percentile_5> and 95th percentile <value_percentile_95>. Assigns -1 for lower bound outliers, 1 for upper bound outliers, and 0 for non-outliers.

Example Query


WITH sample AS (
SELECT col,3.1 value_percentile_5,87.5 value_percentile_95 
FROM UNNEST(ARRAY[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,90,134]) AS col

)
SELECT `justfunctions.eu.outliers_percentiles`(col, value_percentile_5, value_percentile_95)
FROM sample
                                            
/*--Output--
['−1', '−1', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
*/

Statement

CREATE OR REPLACE FUNCTION `your_project_id.your_dataset_id.outliers_percentiles`(`col` FLOAT64, `value_percentile_5` FLOAT64, `value_percentile_95` FLOAT64) 
  RETURNS INT64 AS (CASE 
WHEN 
col < value_percentile_5 THEN -1
WHEN 
col > value_percentile_95 THEN 1 
ELSE 0 
END
)
  OPTIONS ( description = '''Detects if a <value> is an outlier based on then 5th percentile <value_percentile_5> and 95th percentile <value_percentile_95>. Assigns -1 for lower bound outliers, 1 for upper bound outliers, and 0 for non-outliers.''')

Regions

justfunctions.eu.outliers_percentiles(col, value_percentile_5, value_percentile_95),
justfunctions.us.outliers_percentiles(col, value_percentile_5, value_percentile_95)

Type

SQL User Defined Function (SQL UDF)

How to Use

Frequently Asked Questions

User-Defined Functions (UDFs) in Google BigQuery are custom functions that you can create to perform operations that aren't available through the standard SQL functions. These UDFs allow you to extend BigQuery's SQL capabilities to suit your specific data processing needs. JustFunctions is a collection of open-source user-defined functions (UDFs).

JustFunctions is a collection of open-source User-Defined Functions (UDFs) designed to extend the capabilities of Google BigQuery. These functions cover a wide range of applications, including text manipulation, URL processing, date processing, email handling, similarity measures, and more. Moreover, JustFunctions is frequently updated to include more use cases.

We welcome any feedback or questions you may have. You can Contact us or report an issue on Github.

Functions and procedures from JustFunctions can be used directly in any of your projects.
To start, simply click 👆 on any function,  Copy  the 'Example Query' and run it in your BigQuery console.
You can also  Copy  the 'Statement' to create your own private user-defined function.

Yes, JustFunctions is completely free to use.

Yes, currently JustFunctions is only available for Google BigQuery. In the future, we will also support PostgreSQL.

See something wrong? Contact us or report an issue on Github.