How to Perform a Safe DIVIDE in Power BI (DAX and Power Query)

Division is a common operation in Power BI, but it can cause errors when the divisor is zero. Both DAX and Power Query provide built-in ways to handle these scenarios safely.

Safe DIVIDE in DAX

In DAX, the DIVIDE function is the recommended approach. Its syntax is:

DIVIDE(numerator, divisor [, alternateResult])

If the divisor is zero (or BLANK), the function returns the optional alternateResult; otherwise, it performs the division normally.

Examples:

  • DIVIDE(10, 2)5
  • DIVIDE(10, 0)BLANK
  • DIVIDE(10, 0, 0)0

This makes DIVIDE safer and cleaner than using conditional logic.

Safe DIVIDE in Power Query

In Power Query (M language), you can use the try … otherwise expression to handle divide-by-zero errors gracefully. The syntax is:

try [expression] otherwise [alternateValue]

Example:

try [Sales] / [Quantity] otherwise 0

If the division fails (such as when Quantity is zero), Power Query returns 0 instead of an error.

Using DIVIDE in DAX and try … otherwise in Power Query ensures your division calculations remain error-free.

Leave a comment