Formulas: Allow error handling though lazy evaluation in formulas

Hey guys,

Trying to implement an AVERAGE IF function and ran into an error I think is related to Formulas not using lazy evaluation. If I can hack my way around this - please let me know, otherwise want to submit this as a feature request.

Request: In formulas like IF and SWITCH all the functions should not be evaluated (use lazy evaluation) and work like any normal programming language (or Excel even).

To reproduce my problem try:

IF({number_col} = 0, “Avoid error”, 1 / {number_col})
SWITCH({number_col}, 0, “Avoid error”, 1 / {number_col})
These both throw errors even though the divide by zero case was handled for rows where the number_col is zero.

My use-case if creating an AVERAGE IF of columns that may or may not contain values. Works for columns with at least one value but throws an error that I caught already. My psuedo code is basically

IF COUNT = 0 → “Catch”
ELSE SUM / COUNT

Thanks!

Found a solution here.

You basically need to do

IF COUNT = 0 → “Catch”
ELSE → SUM / IF(COUNT = 0, 1, COUNT)

Still think this is dumb, but a workaround at least :slight_smile: