Forum Discussion

shanestocks's avatar
shanestocks
Helper I
2 years ago
Solved

Weird Rounding Error

Hi all, wanting to perform a very, very simple comparison with the following:

 

In the "Overuse" column the top record is showing 716 but that's not correct. The DAX is:

 

= ([Usage (KG)] - [Req (KG)]) * [Act. (EUR)]. The top then, (12,544 - 12,392) * 4.744 = 721.

 

Can I ask how on earth this isn't working please? The [Act. (EUR)] calculation is:

 

=VAR weightedPrice = SUMX(fUsage,fUsage[req_qty] * fUsage[meat_price])
VAR reqTotal = sum(fUsage[req_qty])

RETURN

ROUND(DIVIDE(weightedPrice,reqTotal),3)

 

The raw data is:

 

order_numberproductionreq_qtyusage_qtydate_of_productionp_codemeat_codestandard_pricemeat_price
3105638990880281004/12/2023P10000RM00234.984.605
3105669546040640507/12/2023P10000RM00234.984.605
3105698791981281811/12/2023P10000RM00234.984.605
3105731688578278014/12/2023P10000RM00234.984.605
3105763891981283118/12/2023P10000RM00234.984.605
3105773545440140019/12/2023P10000RM00234.984.605
3105826146040640527/12/2023P10000RM00234.984.605
3105887144839640503/01/2024P10000100826334.984.98
31059168675596599.506/01/2024P10000RM00234.984.605
3105932813171163117008/01/2024P10000100826334.984.98
3105996285175276013/01/2024P10000RM00234.984.605
3106009985175276515/01/2024P10000100826334.984.98
3106069013621203120020/01/2024P10000RM00234.984.605
3106112991981281024/01/2024P10000RM00234.984.605
3106140313221168120027/01/2024P10000100826334.984.98
3106188212801131118531/01/2024P10000100826334.98

4.98

 

Thank you so much

  • 12,544 is not the real value.  It's a rounded display value.  That's what I tried to guide you to with my previous answer.

    The real sum is 12543.50.

    Subtracting 12392 from 12543.50 equals 151.5.  This could be rounded to 151 or 152 .  Multiply those values by 4.98 and you get close to 752 and 757.  So that explains what you're seeing.  And, as before, the Overuse measure is being displayed as a whole number so it's being rounded for display purposes.

    --

    So what to do about it? First, look at the display format of each measure. Click on the measure in the data pane (on  the right) and the MeasureTools ribbon appears. Look at the Format section.  Powerbi makes assumptions here with data type (and decimal places, if applicable).  You can over-ride these choices.  Remember, this is for display.  The 'real' values are held behind the scenes. 

    In your case, the display values have been rounded for display and that's leading to confusion.

     

     

3 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    There's plenty of scope for rounding issues due to the number of different measures involved.

    Item 1 for investigation :   Usage (kg) in the visual = 12544.

    but there's a 599.5 value in the data so something's been rounded there.

     

    • shanestocks's avatar
      shanestocks
      Helper I

      Hi HotChilli thank you for response. So to avoid this what can I best do? The DAX I use merely contains the calculations, but in the visual display I am choosing "whole number", so I am not rounding anything up, but something is definitely amiss and I simply cannot find it. 

       

      The only DAX I am using for this calculation is 3 measures:

       

      [Total Usage]

       

      =SUM(fUsage[usage_qty])

       

      [REQ (KG)]

       

      =SUM(fUsage[req_qty])

       

      ACTUAL COST [Act. (EUR)] - (This returns weighted average)

       

      =VAR weightedPrice = SUMX(fUsage,fUsage[req_qty] * fUsage[meat_price])
      VAR reqTotal = sum(fUsage[req_qty])

      RETURN

      ROUND(DIVIDE(weightedPrice,reqTotal),3)

       

      OVERUSE (EUR)

       

      =([Total Usage]-[Req (KG)])*[Act. (EUR)]

       

      Interestingly, I also get the same issue when using the standard price which is a fixed value...

       

       

      (12,544-12,392) * 4.980 = 757, not the 752 shown.

       

      Any help would be greatly appreciated, I have spent many days on this and cannot find a solution.

       

  • HotChilli's avatar
    HotChilli
    Community Champion

    12,544 is not the real value.  It's a rounded display value.  That's what I tried to guide you to with my previous answer.

    The real sum is 12543.50.

    Subtracting 12392 from 12543.50 equals 151.5.  This could be rounded to 151 or 152 .  Multiply those values by 4.98 and you get close to 752 and 757.  So that explains what you're seeing.  And, as before, the Overuse measure is being displayed as a whole number so it's being rounded for display purposes.

    --

    So what to do about it? First, look at the display format of each measure. Click on the measure in the data pane (on  the right) and the MeasureTools ribbon appears. Look at the Format section.  Powerbi makes assumptions here with data type (and decimal places, if applicable).  You can over-ride these choices.  Remember, this is for display.  The 'real' values are held behind the scenes. 

    In your case, the display values have been rounded for display and that's leading to confusion.