How to Calculate Percentage Using DAX in Power BI
To calculate a percentage in Power BI using
DAX, create a measure that divides a part value by a total value and multiply by 100. For example, use Percentage = DIVIDE(SUM(Table[Part]), SUM(Table[Total])) * 100 to get the percentage result.Syntax
The basic syntax to calculate percentage in DAX is:
Percentage = DIVIDE(Numerator, Denominator) * 100
Where:
- Numerator is the part or subset value you want to measure.
- Denominator is the total or whole value.
DIVIDE()safely handles division and avoids errors if the denominator is zero.- Multiplying by 100 converts the fraction to a percentage.
DAX
Percentage = DIVIDE(SUM(Table[Part]), SUM(Table[Total])) * 100Example
This example shows how to calculate the percentage of sales for a product category compared to total sales.
DAX
Total Sales = SUM(Sales[Amount])
Category Sales = SUM(Sales[Amount])
Category Sales % = DIVIDE([Category Sales], [Total Sales]) * 100Output
If Total Sales = 1000 and Category Sales = 250, then Category Sales % = 25
Common Pitfalls
Common mistakes when calculating percentages in DAX include:
- Not using
DIVIDE()and instead using simple division (/), which can cause errors if the denominator is zero. - Forgetting to multiply by 100, resulting in a decimal fraction instead of a percentage.
- Using incorrect aggregation functions, like mixing
SUM()andCOUNT()inconsistently. - Not considering filter context, which can change totals unexpectedly.
DAX
Wrong = SUM(Sales[Amount]) / SUM(Sales[Total]) -- May cause divide by zero error
Right = DIVIDE(SUM(Sales[Amount]), SUM(Sales[Total])) * 100Quick Reference
| Concept | Description | Example |
|---|---|---|
| DIVIDE() | Safe division avoiding errors if denominator is zero | DIVIDE(SUM(Table[Part]), SUM(Table[Total])) |
| Multiplying by 100 | Converts decimal to percentage | DIVIDE(...) * 100 |
| SUM() | Aggregates values for numerator or denominator | SUM(Sales[Amount]) |
| Filter Context | Affects totals and percentages dynamically | Use measures inside visuals |
Key Takeaways
Use DIVIDE() in DAX to safely calculate percentages and avoid division errors.
Always multiply the division result by 100 to convert to a percentage.
Ensure numerator and denominator use consistent aggregation functions like SUM().
Remember filter context affects your percentage results in reports.
Test your measures with sample data to verify correct percentage output.