Stop 07 · DAX FundamentalsTopics · 8/10

DIVIDE for Safe Division

Part of the Power BI Roadmap

In short

A new store has zero sales this month, and your margin card suddenly shows "Infinity" or "NaN". DIVIDE avoids that with one simple change.

DIVIDE(numerator, denominator) returns a blank or an alternate value instead of an error when the denominator is zero or blank, so it's the safe way to calculate ratios.

The jaadu holds a cake knife over a whole cake at an empty party table, shrugging calmly and setting the knife down beside the untouched plates.

Think of it like this

Sharing a cake with nobody

Cut a cake for four friends and each gets a quarter. Cut it for zero friends and the question makes no sense. A sensible host says "no slices to give" instead of panicking. DIVIDE is that host: when the denominator is zero or blank, it calmly returns blank or a value you choose.

Watch it happen

The / operator vs DIVIDE

[Profit] / [Sales]

  • Sales = 0 gives Infinity
  • 0 / 0 gives NaN
  • Ugly values in cards and tables
  • Needs IF checks to avoid

DIVIDE ( [Profit], [Sales] )

  • Sales = 0 or blank gives blank
  • Optional third value, like 0
  • Blank rows disappear from visuals
  • Short and readable

Use DIVIDE whenever the denominator could be zero or blank. Use / only when it can never be, like dividing by 100.

The big ideas

What you need to know

DIVIDE ( a, b )

Returns a / b, or blank when b is zero or blank.

Alternate result

DIVIDE ( a, b, 0 ) returns 0 instead of blank. Use it only when zero is the honest answer.

Blank hides rows

Visuals drop rows where all measures are blank, which keeps tables clean.

Ratios everywhere

Margin %, conversion rate, average bill value and growth % are all divisions.

See it in code

Walk through the code

dax
1Margin % =2DIVIDE ( [Total Sales] - [Total Cost], [Total Sales] )3 4Avg Bill Value =5DIVIDE ( [Total Sales], [Bills] )6 7Return Rate % =8DIVIDE ( [Returned Qty], [Total Qty], 0 )9 10-- Plain division is fine when the denominator is a constant11Sales in Lakh = [Total Sales] / 100000

1/4A store with no sales gets a blank margin, not Infinity.

Ratios with DIVIDE, plus a case where plain / is fine.

Save yourself the pain

Common mistakes

Oops

Writing IF ( [Sales] = 0, 0, [Profit] / [Sales] ).

Do this instead

DIVIDE ( [Profit], [Sales] ) does the same check, more clearly, and also handles blanks.

Oops

Always setting the alternate result to 0.

Do this instead

A 0% margin and 'no sales' are different stories. Leave it blank unless zero is truly correct.

Your mission

Break and fix a ratio

~10 min

Quick check

What does DIVIDE ( 500, 0 ) return?

Go deeper

  1. 1Write a Profit Margin % measure with DIVIDE.
  2. 2Use the optional third argument to return 0 where it makes sense.
  3. 3Format the measure as a percentage.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge