(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to use DIVIDE in DAX to avoid division by zero

João Barros 06 de July de 2026 4 min read

When you build measures such as profit margin, conversion rate or average order value, you divide one value by another all the time. The problem shows up when the denominator is zero or blank: with the / operator, Power BI returns an error or the value Infinity, which breaks the visual. The DIVIDE function in DAX was made to solve exactly this and to avoid any division-by-zero error, and it is one of the first best practices every report author should master.

Prerequisites

  • Power BI Desktop installed (the same applies to Power Pivot in Excel or to Microsoft Fabric).
  • A model with a table of numeric values. In this example we use a Vendas (sales) table with the columns Receita (revenue) and Custo (cost).
  • Knowing how to create a measure: right-click the table and choose New measure.

Step 1: Understand the division-by-zero problem

Imagine you want to calculate the margin by dividing profit by revenue. A direct measure using the / operator would look like this:

Margem sem DIVIDE = ( SUM(Vendas[Receita]) - SUM(Vendas[Custo]) ) / SUM(Vendas[Receita])

As long as there is revenue, the calculation works. But it only takes one row where revenue is 0 or blank — a new product, a month with no sales — for the result to turn into an error or Infinity. In a matrix, that cell shows a warning and makes the report look unprofessional.

Step 2: Learn the syntax of the DIVIDE function

DIVIDE was created precisely to handle these cases. The syntax has three arguments, the last one being optional:

DIVIDE( <numerator>, <denominator> [, <alternateresult>] )

When the denominator is 0 or BLANK, DIVIDE does not raise any error: it returns the alternate result. If you don't provide one, the default returned value is BLANK. The numerator and the denominator can be columns, measures or full expressions.

Step 3: Create the measure with DIVIDE

Let's rewrite the margin safely. To keep the example readable, we first create two helper measures:

Total Receita = SUM(Vendas[Receita])
Total Custo = SUM(Vendas[Custo])

Now the margin, this time with the DIVIDE function in DAX:

Margem % = 
DIVIDE(
    [Total Receita] - [Total Custo],
    [Total Receita]
)

Whenever revenue is 0 or blank, the measure returns BLANK instead of blowing up with an error. All that's left is to format the measure as a percentage, on the Measure tools tab, and you can use it in any visual.

Step 4: Choose the alternate result

Sometimes we want to show a number instead of an empty cell — for example, a 0 when there are no sales yet. Just fill in the third argument:

Margem % com zero = 
DIVIDE(
    [Total Receita] - [Total Custo],
    [Total Receita],
    0
)

The choice depends on your goal. Leave it as BLANK (without the third argument) when you want visuals to hide rows with no data automatically. Use 0 when you really need a number, for example to sort a table or to reuse the value in another calculation.

Step 5: DIVIDE instead of the "/" operator

The difference boils down to two lines:

  • The / operator returns an error or Infinity when the denominator is 0.
  • DIVIDE detects that case and returns the alternate result, with no errors.

That is why Microsoft's recommendation is to use DIVIDE whenever there is the slightest chance the denominator could be zero or null. In practice, that means almost every ratio in a real report.

Check the result

Place a matrix in the report with the products on the rows and the Margem % measure in the values. Make sure at least one product has no revenue. If you compare the two versions, the measure with / shows an error or Infinity on that row, while the measure with DIVIDE shows an empty cell (or 0, if you used the third argument). If no error warning appears, the calculation is correct.

Conclusion

With DIVIDE you get robust measures for any indicator that involves a ratio — margin, conversion rate, average order value or ROI — without worrying about zero denominators. The next step is to review your old measures and replace the / operators with DIVIDE wherever it makes sense. One final tip: prefer leaving the result as BLANK when you want charts to ignore empty rows on their own. So, which of your measures will you fix first?