Forum Discussion

powerbidu's avatar
powerbidu
Frequent Visitor
1 year ago
Solved

Does PowerBI apply rounding when applying aggregations (SUM)?

Hi all

 

I have the below sample data set. 

 

IdentifierValue
A0.05
A0.2925
A0.1575
A0.065
A0.034
A0.065
A0.136
A0.1
A0.1
B0.034
B0.2925
B0.136
B0.1
B0.1575
B0.1
B0.065
B0.05
B0.065

 

I plotted a table with two columns -  'Identifier' and 'Sum' and am interested to flag out exceptions. Exceptions are identifiers whose total sum of all rows does not equal to 1.

 

 

In the above 2 instances, the sum of all rows with Identifiers A / B add up to 1 in Excel. However it flags as an exception when applied in PowerBi. Can anyone explain to me why that might be the case (I am thinking it could be a rounding issue in Powerbi) and whether there are any ways to resolve this? I do not want Identifiers A / B to be flagged as exceptions.

 

Thanks in advance.

  • Hi powerbidu 

    Column values of type "Decimal number" are inherently approximate,  and comparing two Decimal number values for equality may give unexpected results (see documentation here).

     

    Potential solutions:

    1. Change the Value column to type "Fixed decimal number", which can represent values with at most four decimal places, and is internally stored as an integer value divided by 10^4.

     

    2. Leave Value's type as "Decimal number" but create a flag with tolerance built-in.

    For example:

    Flag = 
    VAR Tolerance = 1E-8
    VAR ResultBool =
        ABS ( SUM ( Data[Value] ) - 1 ) > Tolerance
    VAR ResultInt =
        INT ( ResultBool )
    RETURN
        ResultInt

    Then add a visual-level filter of Flag = 1:

     

    Having said all that, I couldn't replicate your issue with the sample data your posted. Both appeared to sum to exactly 1 for both Identifiers A & B with a column of Decimal number type. However, in general, it's best not to rely on decimal values summing exactly to a particular value.

     

    Do any of the above work for you?

2 Replies

  • Hi powerbidu 

    Column values of type "Decimal number" are inherently approximate,  and comparing two Decimal number values for equality may give unexpected results (see documentation here).

     

    Potential solutions:

    1. Change the Value column to type "Fixed decimal number", which can represent values with at most four decimal places, and is internally stored as an integer value divided by 10^4.

     

    2. Leave Value's type as "Decimal number" but create a flag with tolerance built-in.

    For example:

    Flag = 
    VAR Tolerance = 1E-8
    VAR ResultBool =
        ABS ( SUM ( Data[Value] ) - 1 ) > Tolerance
    VAR ResultInt =
        INT ( ResultBool )
    RETURN
        ResultInt

    Then add a visual-level filter of Flag = 1:

     

    Having said all that, I couldn't replicate your issue with the sample data your posted. Both appeared to sum to exactly 1 for both Identifiers A & B with a column of Decimal number type. However, in general, it's best not to rely on decimal values summing exactly to a particular value.

     

    Do any of the above work for you?