Code action DI015
(Improvement) Replace IF with DIVIDE
Description
Use the DIVIDE
function instead of IF
, to more easily check for zero or blank in the demoninator.
Example 1
Change:
IF([Total Cost] = 0, BLANK(), [Total Sales] / [Total Cost])
To:
DIVIDE([Total Sales], [Total Cost])
Example 2
Change:
IF([Total Cost] <> 0, [Total Sales] / [Total Cost])
To:
DIVIDE([Total Sales], [Total Cost])
Why is Tabular Editor suggesting this?
The DIVIDE
function is a more concise and readable way to handle division by zero or blank values. By using DIVIDE
, you make your code more robust and easier to understand. Moreover, the DIVIDE
function is more efficient than using IF
to check for zero or blank values, as it only evaluates the denominator once.