Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Last active February 17, 2024 15:26
Show Gist options
  • Select an option

  • Save cbaragao/5a4241bbf7c57aeb25df22041f083376 to your computer and use it in GitHub Desktop.

Select an option

Save cbaragao/5a4241bbf7c57aeb25df22041f083376 to your computer and use it in GitHub Desktop.
(val as number, col as list) =>
let
l = List.Sort(col),
count = List.Count(l),
q1 = count * 0.25,
q2 = count * 0.5,
q3 = count * 0.75,
fnRunCheck = (check as number)=>
let
get_q = if check = Number.IntegerDivide(check,1) then List.Average({l{Number.Round(check,0)-1}, l{Number.Round(check,0)}}) else l{Number.Round(check,0)}
in
get_q,
q1_val = fnRunCheck(q1),
q2_val = fnRunCheck(q2),
q3_val = fnRunCheck(q3),
iqr =q3_val - q1_val,
return = [
quartile = if val <= q1_val then 1 else if val <= q2_val then 2 else if val <= q3_val then 3 else 4,
q1= q1_val,
q2 = q2_val,
q3 = q3_val,
interquartile_range = iqr,
outlier = if val < q1_val - (1.5*iqr) then true else if val > q3_val + (1.5 * iqr) then true else false
]
in
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment