Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
croberts21
Continued Contributor
Continued Contributor

How to calculate percent and avoid divide by zero?

I'm still pretty new to PBI. I have Free PBI Desktop v2.100.1182 (64 bit free version Dec 2021) on Windows 10. I use an ODBC driver to connect to a Postgresql database server.

 

I want to make a measure in a table viz which will calculate a percent based on the sum of a row. However, sometimes the numerator sums to zero, blank or null, sometimes the denominator sums to zero, blank or null. Right now my measure is: 

JobCost[aaEstCostSum] / JobCost[aaActCostSum]

 

And some of the percents are "Infinite" or "NaN". Like in this screenshot. (Using fake data.)

croberts21_0-1647968039303.png

 

 

Basically I would like to do this in the measure but I don't know how.

 

PctOfEstCost = If(INUMBER(JobCost[aaEstCostSum])=True and ISNUMBER(JobCost[aaActCostSum])=True, JobCost[aaEstCostSum] / JobCost[aaActCostSum], BLANK)

 

I've already searched and read some pages, the DAX reference, and some videos. 

 

So I would need a compound IF statement but the DAX documentation doesn't given an example of a compound IF statement.

 

Thanks!

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Use the DIVIDE function





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

2 REPLIES 2
PaulDBrown
Community Champion
Community Champion

Use the DIVIDE function





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Wow it works! I'm getting learneded! 🙂

 

Here's how I did it: 

PctOfEstCost = DIVIDE(JobCost[aaEstCostSum], JobCost[aaActCostSum],"")
 
The third parameter is the alt result which is a blank string. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors