Skip to main content
IF_ZERO
Tom Williams avatar
Written by Tom Williams
Updated over a year ago

Type: Function
โ€‹
โ€‹Function: IF_ZERO

Syntax: IF_ZERO(value, fallback_if_zero)

Description: Returns the first value or the second value (fallback) if the first one is equal to 0. The value and its fallback must have the same type.

Sample usage:

  • IF_ZERO(lines_changed, 1) returns 1 instead of lines_changed if the latter is equal to zero. This operator is particularly useful when doing divisions.

  • SUM(deletions)/SUM(IF_ZERO(additions, 1))*100 returns a refactoring ratio (percentage) and handles the case where no lines were added (additions = 0).

Did this answer your question?