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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Mary78
Helper I
Helper I

Expect 0 get -0.000000000000043

Hi All.

I´m geting extrem values sometimes on a Margin% measure, exampel: 750951781615971100.00%
Measure: 

Margin =
DIVIDE (
( SUM ( 'sales'[Net sales] ) - SUM ( 'sales'[Cost] ) ),
SUM ( 'sales'[Net sales] ),
0
)

When trubleshooting I´ve found that  'sales'[Net sales] sometime instead of being 0 is very smal ex, -0.000000000000043.
In data source (SQL database) [Net sales] is deffined as : Decimal(20,6) and value for the Example are 00.000000 


 So when pulling in the data Power BI is sometimes turning 0.000000 into -0.000000000000043 or similar.

Does any one know what´s going wrong and how to fix it?

BR Måns


1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Mary78 ,

 

The problem is usually to do with how computers handle floating point numbers within a binary context. Tom Scott explains it beautifully here:
https://www.youtube.com/watch?v=PZRI1IfStY0 

 

The solution is to round off your numbers in the transformation process. For example, in Power Query, your would apply a transformation similar to this on all of your decimal columns:

Number.Round([DecimalColumn], 2)

This should force the tiny translation roundings to be truncated.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @Mary78 ,

 

The problem is usually to do with how computers handle floating point numbers within a binary context. Tom Scott explains it beautifully here:
https://www.youtube.com/watch?v=PZRI1IfStY0 

 

The solution is to round off your numbers in the transformation process. For example, in Power Query, your would apply a transformation similar to this on all of your decimal columns:

Number.Round([DecimalColumn], 2)

This should force the tiny translation roundings to be truncated.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks for answer, rounding solves issue with extrem results from measure. 👍
But is it really possible that a 0.000000 can turn in to  -0.000000000000043 due to floting point issue?

Most zeros in data is not turnd into super low values. Could it not be that the underlying data in this case isn´t acctualy 0.000000 but infact -0.000000000000043 rounded to 0.000000?

Of course if we find -0.000000000000043 in underlying data this could be due to floting point but I´m just oparating in PBI 

 

It looks like, in your example, you're deducting sales[Cost] from sales[Net Sales] to get your Margin value. My guess would be that your [Net Sales] value is actually dead zero, but one/some/all of your [Cost] values have this floating point issue, hence why you get a negative tiny number.

It's possibly due to a calculation at source that produces the [Cost] values. For example, it may actually be calculated at source as [Total Cost] / [Unit Quantity] or similar, thus inviting a floating point issue.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors