outliers_iqr - BigQuery

Function

outliers_iqr(col, value_percentile_25, value_percentile_75)

Description

Outliers Iqr - Detects if a <value> is an outlier based on the IQR method, using the 25th percentile <value_percentile_25> and 75th percentile <value_percentile_75>.

Example Query


WITH sample AS (
SELECT col,11.5 value_percentile_25,32.5 value_percentile_75 
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_iqr`(col, value_percentile_25, value_percentile_75)
FROM sample
                                            
/*--Output--
[0, 0, 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_iqr`(`col` FLOAT64, `value_percentile_25` FLOAT64, `value_percentile_75` FLOAT64) 
  RETURNS INT64 AS (CASE 
WHEN 
col < value_percentile_25 - 1.5 * (value_percentile_75 - value_percentile_25) THEN -1
WHEN 
col > value_percentile_75 + 1.5 * (value_percentile_75 - value_percentile_25) THEN 1 
ELSE 0 
END
)
  OPTIONS ( description = '''Detects if a <value> is an outlier based on the IQR method, using the 25th percentile <value_percentile_25> and 75th percentile <value_percentile_75>.''')

Regions

justfunctions.eu.outliers_iqr(col, value_percentile_25, value_percentile_75),
justfunctions.us.outliers_iqr(col, value_percentile_25, value_percentile_75)

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.