Sub topic 8
Handling Zero and Blank Denominators with an Alternate Result
This chapter assumes you can create a measure in Power BI Desktop and that you have already written Total Sales and Order Lines from the earlier chapters. It also assumes you know that a report's slicers and visuals change the rows a measure sees. If those ideas are new, review them first.
A ratio has a weak point: the denominator can be empty. A slicer selection, a row in a matrix, or a date range can leave no rows to count. This chapter covers what DIVIDE returns in that case, how to change the result with the third argument, and when changing it makes a report worse.
The problem: dividing by nothing
Here is the ratio measure from the previous chapter:
Average Sales per Order Line = DIVIDE([Total Sales], [Order Lines])Suppose a matrix shows one row per product category. One category, "Accessories", has no sales in the selected year. For that row, [Order Lines] is zero or blank. A plain division would be [Total Sales] / [Order Lines], and the / operator does not fail politely.
| Expression | Result with the `/` operator |
|---|---|
| 500 / 0 | Infinity |
| 0 / 0 | NaN |
| 500 / BLANK | Infinity |
| BLANK / BLANK | BLANK |
Infinity and NaN ("not a number") appear in your visuals as text, and they break charts that need numeric values. DIVIDE checks the denominator first, so those values never appear.
How DIVIDE decides
DIVIDE takes up to three arguments:
- The numerator.
- The denominator.
- An optional alternate result.
It tests the denominator. If the denominator is zero or blank, it returns the alternate result. Otherwise it returns the ordinary quotient. When you leave out the third argument, the alternate result is BLANK.
Average Sales per Order Line = DIVIDE([Total Sales], [Order Lines])This returns BLANK for any filter selection where [Order Lines] is zero or blank. To return a number instead, supply the third argument:
Average Sales per Order Line (0 if none) = DIVIDE([Total Sales], [Order Lines], 0)Now the same selection shows 0.
What triggers the alternate result
Only the denominator is tested. This table shows the common cases, using DIVIDE(n, d, 0).
| Numerator | Denominator | Result | Why |
|---|---|---|---|
| 500 | 4 | 125 | Normal division. |
| 500 | 0 | 0 | Denominator is zero, so the alternate result is used. |
| 500 | BLANK | 0 | A blank denominator is treated like zero. |
| 0 | 4 | 0 | Real zero from normal division. The alternate result was not needed. |
| BLANK | 4 | BLANK | The denominator is valid, so the alternate result does not apply. |
The last two rows matter. If the numerator is blank but the denominator is valid, DIVIDE returns BLANK, not your alternate result. A category with order lines but no sales amounts would therefore still show blank. If you want zero in that case too, you must handle the numerator separately, for example by adding zero to it: DIVIDE([Total Sales] + 0, [Order Lines], 0). In DAX, BLANK() + 0 evaluates to 0. Check the result against your own model before relying on it, because it changes the meaning of "no data" for that measure.
Why a blank denominator happens
Both numbers come from the filter context. Consider a Sales table and a Region slicer. If you select a region that has no rows in the chosen date range, then:
[Total Sales]sums nothing, so it returns BLANK.[Order Lines]counts nothing, so it returns zero or blank.DIVIDEsees an empty denominator and returns the alternate result.
You do not need to write extra logic for this. The check happens in every cell of every visual, each time the filter context changes. That is the main reason to prefer DIVIDE over / in report measures: you cannot know in advance which combination of filters a user will pick.
Choosing BLANK or 0
The default BLANK and an explicit 0 look similar in a formula, but they behave differently in a report.
What BLANK does in visuals
Power BI hides rows and chart categories whose measures are all blank. A table of products with the default DIVIDE shows only products that have sales. Charts skip the empty points, and lines connect the points that exist. That is often what a reader wants.
What 0 does in visuals
A measure that returns 0 is never blank, so every category stays on screen. Suppose a table lists 5,000 products and you add the (0 if none) measure. Products with no sales now appear as rows with zero, and the table may grow far beyond the products that matter. Line charts also draw a dip to zero at each empty date, which looks like a collapse in performance.
The meaning of the number
Zero says "we measured and the answer is zero." BLANK says "there is nothing to measure." For an average sales per order line, no order lines means the average is undefined, not zero. Showing 0 can mislead someone who compares categories or averages across rows.
Use these guidelines:
- Use the default BLANK when "no data" is a real state and you want empty categories hidden.
- Use
0when a downstream calculation or a visual requires a number, or when zero really is the correct business answer, such as a target-attainment percentage when nothing was attempted. - Use another constant, such as
-1, only if some other tool reads the value and needs a marker. Do not show it to people.
Comparing DIVIDE with a hand-written IF
You can get the same behavior with IF:
Average Sales per Order Line (IF) =
IF(
[Order Lines] = 0,
0,
[Total Sales] / [Order Lines]
)This works for the zero case. In DAX, a blank compared with 0 using = is treated as equal, so [Order Lines] = 0 is true for a blank denominator too. The measure is longer, though. It repeats [Order Lines] twice, and the intent ("avoid dividing by zero") is spread across three arguments. DIVIDE states the same intent in one call. When another author reads your model, DIVIDE also signals that the zero case has been considered, while a bare / raises the question of whether it was missed.
There is one case where the / operator is acceptable: when you know the denominator can never be zero or blank, for example dividing by a constant like / 100. In every other case, use DIVIDE.
Worked example: testing both versions
To see the difference yourself, build both measures and compare them.
- Make sure these measures exist:
Total Sales = SUM(Sales[SalesAmount])Order Lines = COUNTROWS(Sales)- Add the two ratio measures:
Average Sales per Order Line = DIVIDE([Total Sales], [Order Lines])Average Sales per Order Line (0 if none) = DIVIDE([Total Sales], [Order Lines], 0)- Create a matrix with a category field on rows and add both ratio measures as values, together with
[Order Lines]. - Add a slicer for year or region. Pick a selection where at least one category has no sales.
- Observe the rows. The first measure drops the empty category if it is the only measure in the matrix, and shows a blank cell if other measures still have values. The second shows
0for that category and keeps the row visible.
Keep the [Order Lines] column in the matrix while testing. It lets you confirm that the alternate result appears exactly where the denominator is empty.
Other denominators that can be zero
The alternate result works for any ratio, not just averages. Here is a conversion-style measure over a filtered table, using the pattern from the filtered-count chapter:
Large Order Lines = COUNTROWS(FILTER(Sales, Sales[SalesAmount] > 1000))Large Order Share = DIVIDE([Large Order Lines], [Order Lines])Here the numerator can legitimately be zero while the denominator is not, which returns a true 0 through ordinary division. Only when [Order Lines] is empty does the alternate result apply. Because Large Order Share is a ratio, format it as a percentage in the measure's format settings. The alternate result of 0 then displays as 0%.
Common mistakes
- Using
/in report measures. The first empty slicer selection produces Infinity or NaN in a visual. - Setting the alternate result to 0 everywhere by habit. This keeps every category on screen and can turn a focused table into a long list of zeros. Choose deliberately for each measure.
- Expecting the alternate result for a blank numerator. It applies only to the denominator.
- Mixing up a real zero and a substituted zero. Once you return
0for "no data," readers cannot tell it from a measured zero. If the difference matters, keep BLANK. - Testing only with all data selected. The problem appears under narrow filters. Always test with a slicer selection that removes most rows.
Exercises
Exercise
A matrix shows DIVIDE([Total Sales], [Order Lines]) by category. One category has no rows in the selected year. What does that category's cell show, and why?
Show answer
It shows blank. [Order Lines] is zero or blank for that category, so DIVIDE returns its alternate result, which defaults to BLANK when no third argument is given. If no other measure in the visual has a value for the category, the whole row is also hidden.
Exercise
You change the measure to DIVIDE([Total Sales], [Order Lines], 0). A colleague says the table now has hundreds of extra rows. Explain why, and name one situation where you would still choose the BLANK version.
Show answer
The measure now returns 0 instead of BLANK, so it has a value for every category. Power BI hides only rows where all measures are blank, so categories with no sales stay visible with 0. Choose the BLANK version when "no data" is a real state and empty categories should be hidden, for example an average, where zero would falsely suggest a measured average of zero.
Exercise
What does DIVIDE(BLANK(), 4, 0) return, and why is the alternate result not used?
Show answer
It returns BLANK. The alternate result applies only when the denominator is zero or blank. Here the denominator is 4, so DIVIDE performs normal division, and a blank numerator gives a blank result.