Table of Contents

Code action DI014 (Improvement) Replace IFERROR with DIVIDE

Description

Use the DIVIDE function instead of IFERROR to provide an alternate result when a division has a zero demoninator.

Example 1

Change:

DAX
IFERROR([Total Sales] / [Total Cost], BLANK())

To:

DAX
DIVIDE([Total Sales], [Total Cost])

Example 2

Change:

DAX
IFERROR(([Total Sales] - [Total Cost]) / [Total Cost], 1)

To:

DAX
DIVIDE([Total Sales] - [Total Cost], [Total Cost], 1)

Why is Tabular Editor suggesting this?

A common anti-pattern in DAX is to check for division-by-zero errors by using the IFERROR function. This pattern should be avoided, as evaluation errors add overhead to the query execution. Instead, the DIVIDE function should be used, as it checks that the denominator is not zero before the division is carried out. Moreover, using floating point arithmetics, the DIVIDE function is more robust and handles edge cases better than the IFERROR function. By using the DIVIDE function, the code becomes more concise and easier to understand.