Safe Divide function with ability to handle divide by zero case.
Optional. The alternate result to return when dividing by zero.
Result of the division between Numerator and Denominator, or AlternateResult in case there is a division by zero.
Alternate result on divide by 0 must be a constant. By default, the AlternateResult argument is BLANK.
DIVIDE is faster than an IF statement checking whether the denominator is zero. However, DIVIDE is executed in the formula engine and it is not as fast as a native division.
» 2 related functions
-- DIVIDE performs safe division protecting from division by -- zero. In case of zero denominator, it returns its third -- argument that defaults to a blank. DEFINE MEASURE Sales[Unprotected Growth %] = VAR CY = [Sales Amount] VAR PY = CALCULATE ( [Sales Amount], SAMEPERIODLASTYEAR( 'Date'[Date] ) ) RETURN (CY - PY) / PY MEASURE Sales[Protected Growth %] = VAR CY = [Sales Amount] VAR PY = CALCULATE ( [Sales Amount], SAMEPERIODLASTYEAR( 'Date'[Date] ) ) RETURN DIVIDE ( CY - PY, PY, BLANK () ) EVALUATE SUMMARIZECOLUMNS ( 'Date'[Calendar Year], "Unprotected Growth %", [Unprotected Growth %], "Protected Growth %", [Protected Growth %] )
|Calendar Year||Unprotected Growth %||Protected Growth %|
Learn more about DIVIDE in the following articles:
The DIVIDE function in DAX is usually faster to avoid division-by-zero errors than the simple division operator. However, there are exceptions to this rule, described in this article through a simple performance analysis. » Read more
From SQL to DAX: Implementing NULLIF and COALESCE in DAX
This article describes how to implement a syntax equivalent to the T-SQL function NULLIF and the ANSI SQL function COALESCE, in DAX. » Read more
Other related functions are:
Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber,
Microsoft documentation: https://docs.microsoft.com/en-us/dax/divide-function-dax