DIVIDE in DAX: safe division and when to use /

How DIVIDE handles division by zero and BLANK in DAX, the alternate result, why returning BLANK is usually better than 0, when the / operator is the better choice, ratio measures done right (margin %, conversion rate, per customer), and common mistakes.

Short answer: DIVIDE ( numerator, denominator [, alternate] ) divides and returns BLANK (or the alternate result) when the denominator is 0 or BLANK, instead of an error or infinity. Microsoft's guidance: use DIVIDE whenever the denominator is an expression that could be zero or blank, use the / operator when the denominator is a constant ([Revenue] / 1000), and think twice before passing an alternate such as 0, because visuals hide rows where measures are BLANK.

Every ratio in a report (margin %, conversion rate, revenue per customer, growth) is a division, and every one meets a zero somewhere: a new product with no last year, a day without visits.

What does DIVIDE return?

NumeratorDenominatornumerator / denominatorDIVIDEDIVIDE with alternate 0
502000.250.250.25
500InfinityBLANK0
00NaNBLANK0
50BLANKInfinityBLANK0
BLANK200BLANKBLANKBLANK
DIVIDE against the / operator

5 / BLANK is Infinity and 0 / BLANK is NaN in DAX (Microsoft's data types table); DIVIDE avoids both.

How do you write ratio measures?

Margin % = DIVIDE ( [Revenue] - [Cost], [Revenue] )

Conversion Rate = DIVIDE ( [Orders], [Sessions] )

Revenue per Customer = DIVIDE ( [Revenue], [Customers] )

Revenue vs LY % = DIVIDE ( [Revenue] - [Revenue LY], [Revenue LY] )

-- a constant denominator: use the operator
Revenue K = [Revenue] / 1000

Divide aggregates, never sum or average a ratio column: the margin of a total is total margin over total revenue, not the average of line margins (see measures vs calculated columns).

When is an alternate result right?

Microsoft's recommendation is that measures usually return BLANK, because visuals remove groupings where all measures are BLANK. An alternate of 0 brings back every empty combination as a row of zeros. Use an alternate when:

  • a card must show a number, not "(Blank)": DIVIDE ( [Returns], [Orders], 0 ),
  • a downstream calculation needs a number,
  • zero is the true answer (no orders, so no returns rate is meaningful as 0%).

What goes wrong?

  • / with measure denominators. Infinity or errors appear in visuals; use DIVIDE.
  • DIVIDE with constants. Unnecessary checks; use /.
  • Alternate 0 everywhere. Long tables full of zero rows and slower visuals.
  • Growth from a blank base. DIVIDE returns BLANK for new items; label them "new" with an IF ( ISBLANK ( [Revenue LY] ), ... ).
  • Ratios of ratios. Averaging percentages weights small groups like big ones; divide totals.

Where can you check this?

Where do you start?

Search your measures for / [ and replace each measure denominator with DIVIDE. IF and SWITCH covers the other conditions around ratios.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.