Utilize logical functions to apply conditional logic, handle null values, and manage errors in your derived columns. These functions, such as CASE, IF, and COALESCE, enable dynamic data categorization, error handling, and flexible data transformation, allowing you to tailor data outputs based on specific conditions and scenarios.
case(when(yesno_arg, value_if_yes), ...)
case(when(MRR > 1000, "Enterprise"), when(MRR > 500, "Mid-market"), "SMB")
labels customers as “Enterprise” or “Mid-market” based on their MRR, or “SMB” by default.coalesce(value_1, value_2, ...)
coalesce(first_name, username)
would use first_name
if it’s not null, otherwise username
.if(yesno_expression, value_if_yes, value_if_no)
if(status = "Active", "Yes", "No")
returns “Yes” if the status is active, “No” otherwise.is_null(value)
is_null(last_payment_at)
would return Yes if it’s null, indicating a missing payment date.iferror(value, value_if_error)
iferror(total_payments / number_of_payments, 0)
would prevent division by zero errors by returning 0 if number_of_payments
is zero.ifna(value, value_if_na)
ifna(MRR, 0)
could replace #N/A with 0 in revenue calculations.ifs(condition1, value1, condition2, value2, ...)
ifs(diff_months(activated_at, today()) > 12, "Yearly", diff_months(activated_at, today()) > 1, "Monthly", "New")
categorizes them as “Yearly,” “Monthly,” or “New” based on how long ago they were activated.switch(expression, case1, value1, [default or case2, value2, ...])
switch(status_code, 1, "Active", 2, "Paused", 3, "Cancelled", "Unknown")
switch(status_code, 1, "Active", 2, "Paused", 3, "Cancelled", "Unknown")
would return “Active,” “Paused,” or “Cancelled” based on the code, or “Unknown” if there’s no match.