Sub topic 7
Calculating ratios with DIVIDE
This chapter assumes you can work in Power BI Desktop's Report view and the Fields pane. It also assumes you already have a Sales table and the two measures from the previous chapters: Total Sales and Order Lines. Here you will combine them into a ratio.
Why a ratio needs its own function
A ratio divides one number by another, such as sales per order line. You could write it with the / operator. That works until the denominator is zero or blank. The / operator then returns an error or infinity, and visuals that show those values look broken.
DIVIDE is a DAX function that does the division and handles that case for you. Its syntax is:
DIVIDE(<numerator>, <denominator> [, <alternateResult>])If the denominator is zero or blank, DIVIDE returns BLANK() by default. You can pass a third argument to return a different value.
Reusing measures inside a measure
Measures can refer to other measures by name in square brackets. This lets you build a ratio from pieces you have already tested.
Here are the two measures from earlier chapters:
Total Sales = SUM(Sales[SalesAmount])Order Lines = COUNTROWS(Sales)Now combine them:
Average Sales per Order Line = DIVIDE([Total Sales], [Order Lines])This measure divides the sales total by the number of rows in the current filter context. Each part is a separate measure, so you can check them on their own. If the average looks wrong, add Total Sales and Order Lines to a table visual and see which one is off.
Square brackets without a table name mean a measure. A column reference always includes the table, as in Sales[SalesAmount]. Following this convention makes formulas easier to read.
How filter context applies
Each referenced measure is evaluated in the same filter context as the measure that calls it. Suppose a slicer limits the report to the year 2025. Then Total Sales returns 2025 sales, Order Lines counts 2025 rows, and the ratio is the 2025 average. You do not write any filter logic in the ratio itself.
What happens with a zero or blank denominator
Consider a product category with no sales in the selected year. In that context Order Lines is blank, because no Sales rows are visible. The call DIVIDE([Total Sales], [Order Lines]) then returns BLANK(). In most visuals, blank results are left out, so the empty category simply does not appear. This is often what you want.
Sometimes you want a visible zero instead. Use the third argument:
Average Sales per Order Line (0 if none) = DIVIDE([Total Sales], [Order Lines], 0)Now every category shows a value, and those with no data show 0.
Choosing between BLANK and 0
The two results mean different things, so choose on purpose.
| Result | Meaning to the reader | Effect in visuals |
|---|---|---|
| `BLANK()` (default) | No data to average | Rows or points are usually omitted |
| `0` (alternate result) | The average is zero | Rows or points are shown with 0 |
An average of 0 can be misleading when there were no orders at all, because it suggests orders existed and were worth nothing. Use the alternate result when your report must list every category, or when later calculations need a number instead of a blank.
Why not use the / operator
You can write [Total Sales] / [Order Lines]. For a blank denominator, DAX gives an error or infinity, depending on the case. DIVIDE avoids this and states your intent in one place. It is the recommended choice when the denominator can be zero or blank, which is common once slicers narrow the data.
Common errors
- Using column names without a table.
DIVIDE([SalesAmount], [Order Lines])fails, because[SalesAmount]is a column and needsSales[SalesAmount]. Even then, a bare column is not aggregated, so useSUMor an existing measure. - Wrong argument order. The numerator comes first. Swapping the arguments gives the inverse ratio, with no error to warn you.
- Putting 0 in the third argument without thinking. It hides the difference between no data and a true zero.
- Dividing averages of averages. Divide totals by totals, as this measure does, rather than averaging precomputed ratios.
Try it
- Select the
Salestable in the Fields pane and choose New measure. - Enter the
Average Sales per Order Lineformula and press Enter. - Add the measure to a card visual and note the value.
- Add a slicer for a date or category field and change the selection. Watch the card update.
- Pick a selection with no sales rows. Compare the result with the
(0 if none)version.
Exercise
A table visual lists product categories. One category has no Sales rows in the selected year. What does DIVIDE([Total Sales], [Order Lines]) return for it, and how do you make it return 0?
Show answer
It returns BLANK, because Order Lines is blank for that category, so the category is usually omitted from the visual. Pass 0 as the third argument: DIVIDE([Total Sales], [Order Lines], 0).
Exercise
Why is DIVIDE([Total Sales], [Order Lines]) still correct when a slicer is set to one region, even though the formula has no filter in it?
Show answer
Both referenced measures are evaluated in the current filter context. The slicer filters the Sales rows, so Total Sales and Order Lines both reflect that region, and DIVIDE divides the filtered values.