I'm trying to build some stats on a table in snowflake and am using the kurtosis() and skew() functions. Since the calculations are under the hood (the divisions) I cannot use nullif to account for cases where I don't have enough distinct values which will return a Division by zero error. Does Snowflake have some sort of iferror() or is_error() function that I can use to return null or exclude from my table? Or could I build a UDF to do handle this scenario?
EDIT
This is the script I am using
select
f.key colname,
f.path path,
typeof(f.value) type,
count(distinct {player_col}) player_cnt,
count(*) event_cnt,
count(distinct f.value) unique_val_cnt,
min(f.value) min,
round(percentile_cont(.25) within group (order by iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value / 1000000, null)) * 1000000, 2) p25,
round(avg(iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value / 1000000, null)) * 1000000, 2) mean,
round(median(iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value / 1000000, null)) * 1000000, 2) med,
round(percentile_cont(.75) within group (order by iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value / 1000000, null)) * 1000000, 2) p75,
max(f.value) max,
mode(f.value) mode,
iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), max(f.value)-min(f.value), null) range,
round(percentile_cont(.75) within group (order by iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value / 1000000, null)) * 1000000, 2) -
round(percentile_cont(.25) within group (order by iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value / 1000000, null)) * 1000000, 2) iqr,
round(stddev(iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value / 1000000, null)) * 1000000, 2) std,
kurtosis(iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value, null)) kurtosis,
skew(iff(typeof(f.value) in ('DECIMAL', 'INTEGER'), f.value, null)) skewness
from
{json_table},
lateral flatten({json_col}, recursive=>true) f
where
typeof(f.value) not in ('OBJECT', 'NULL_VALUE', 'ARRAY') and f.path not like '%[%]%'
group by 1, 2, 3
order by 1, 2, 3
I get the below error
So I am guessing either some keys have less than 3 values or 1 distinct value across so it would return a DIV0# error.

div0function to handle division by zero error , but doesn't apply to your case , you better look into your data and filter out bad data before doing your math operations