How to Use DIVIDE Function in DAX for Power BI Calculations
Use the
DIVIDE function in DAX to perform division safely by specifying a numerator and denominator. It automatically handles divide-by-zero cases by returning an alternate result you can define, preventing errors in your Power BI reports.Syntax
The DIVIDE function syntax is:
DIVIDE(numerator, denominator, [alternateResult])
numerator: The number to be divided.
denominator: The number to divide by.
alternateResult (optional): The value to return if the denominator is zero or blank. If omitted, it returns blank.
DAX
DIVIDE(<numerator>, <denominator>, [alternateResult])
Example
This example calculates the sales per customer safely, avoiding errors if the number of customers is zero.
DAX
Sales Per Customer = DIVIDE(SUM(Sales[TotalSales]), SUM(Sales[CustomerCount]), 0)Output
If TotalSales = 1000 and CustomerCount = 0, then Sales Per Customer = 0
Common Pitfalls
Common mistakes include dividing directly with / which causes errors if the denominator is zero or blank. Also, forgetting to provide an alternateResult can lead to blank results that confuse report users.
Wrong way:
Sales Per Customer = SUM(Sales[TotalSales]) / SUM(Sales[CustomerCount])
This causes an error if CustomerCount is zero or blank.
Right way:
Sales Per Customer = DIVIDE(SUM(Sales[TotalSales]), SUM(Sales[CustomerCount]), 0)
This returns 0 instead of error.
Quick Reference
| Parameter | Description | Example |
|---|---|---|
| numerator | Value to be divided | SUM(Sales[TotalSales]) |
| denominator | Value to divide by | SUM(Sales[CustomerCount]) |
| alternateResult | Value if denominator is zero or blank | 0 or BLANK() |
Key Takeaways
Use DIVIDE to safely perform division and avoid errors from zero or blank denominators.
Always provide an alternateResult to control what shows when division is not possible.
Avoid using the / operator directly in DAX when denominator might be zero or blank.
DIVIDE improves report reliability and user experience by handling divide-by-zero gracefully.