Forum Discussion

AquilaVictrix's avatar
AquilaVictrix
Regular Visitor
1 year ago
Solved

Total row not showing the correct amount

Hello i have this issue, i have a Measure called  $ / Ton

 

$ / Ton = SUM(BD[MXN]) / SUM(BD[Movidas])

Also this measure called Impacto:

Impacto =

SUMX(

    VALUES('BD'[Ruta]),

    VAR VolumenAuto = CALCULATE(SUM('BD'[Movidas]), 'BD'[Transporte] = "Auto")

    VAR VolumenFFCC = CALCULATE(SUM('BD'[Movidas]), 'BD'[Transporte] = "FFCC")

    VAR CostoPorTonAuto = CALCULATE([$ / Ton], 'BD'[Transporte] = "Auto")

    VAR CostoPorTonFFCC = CALCULATE([$ / Ton], 'BD'[Transporte] = "FFCC")

    RETURN

        IF(VolumenAuto > 0 && VolumenFFCC > 0,

            ROUND((CostoPorTonAuto - CostoPorTonFFCC) * VolumenAuto, 0),

            0

        )

)

In the Rows the value of Imacto is correct and if i compare it with the excel data is all good but  the problem is in the total is not showing the correct amount
In PBI

in Excel;

 

what am i doing wrong in the Impacto Measure? thanks in advance.

 

 

  • AquilaVictrix's avatar
    AquilaVictrix
    1 year ago

    *update* 

    its Weird i have another table with Key Routes thata are conected to the Main BD

    and with this the total is correct:

    Impacto = 

    SUMX(

        VALUES(Rutas[Key]),

        VAR VolumenAuto = CALCULATE(SUM(BD[Movidas]), BD[Transporte] = "Auto")

        VAR VolumenFFCC = CALCULATE(SUM(BD[Movidas]), BD[Transporte] = "FFCC")

        VAR CostoPorTonAuto = CALCULATE([$ / Ton], BD[Transporte] = "Auto")

        VAR CostoPorTonFFCC = CALCULATE([$ / Ton], BD[Transporte] = "FFCC")

        RETURN

            IF(VolumenAuto > 0 && VolumenFFCC > 0,

                ROUND((CostoPorTonAuto - CostoPorTonFFCC) * VolumenAuto, 0),

                0

            )

    )



10 Replies

  • Deku's avatar
    Deku
    Icon for Super User rankSuper User

    I assume this is related to your Round(). In Power BI the total is not the sum of the rows in the table, it is calculated independly. Without more context it is hard to say 

    • AquilaVictrix's avatar
      AquilaVictrix
      Regular Visitor

      yes im trying to show the sum of the rows filtered (showed in the table), but the total is not right
       
       i have this as result, the total in Movidas is on spot but the Impacto is not

      im using cases in the variables:
      in this Var i store the volume of ton moved by truck

      VAR VolumenAuto = CALCULATE(SUM('BD'[Movidas]), 'BD'[Transporte] = "Auto")


      in this var the volume moved by Rail:

          VAR VolumenFFCC = CALCULATE(SUM('BD'[Movidas]), 'BD'[Transporte] = "FFCC")

         And in these, the respective cost per ton moved:

      VAR CostoPorTonAuto = CALCULATE([$ / Ton], 'BD'[Transporte] = "Auto")

      VAR CostoPorTonFFCC = CALCULATE([$ / Ton], 'BD'[Transporte] = "FFCC")


      witch finaly calulates the Impact of using the Trucks in Rail Routes: only if the route has volume moved by truck and rail:

              IF(VolumenAuto > 0 && VolumenFFCC > 0, 

                  ROUND((CostoPorTonAuto - CostoPorTonFFCC) * VolumenAuto, 0),

                  0

              )
      RutaMovidas$ / TonImpacto
      148$390.20$10,729
      2288$260.10$31,109
      3142$145.60$6,431
      42208$359.80$255,937
      5153$955.40$90,485
      6144$190.90$13,085
      7502$292.90$57,928
      835$177.70$1,713
      972$236.10$1,473
      1048$457.40$8,929
      1149$1,111.30$39,255
      12284$423.00$42,207
      13586$913.30$377,486
      14246$967.70$55,280
      1548$707.00$5,602
      16145$3,406.10$232,141
      1748$1,022.60$2,498
      1835$402.70$7,146
      1970$662.40$6,449
      2049$169.90$2,996
      Grand Total5200$13,252.10$1,363,209
  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Hi,

    Please try something like below whether it works.

    Impacto =
    SUMX (
        VALUES ( 'BD'[Ruta] ),
        IF (
            CALCULATE ( SUM ( 'BD'[Movidas] ), 'BD'[Transporte] = "Auto" ) > 0
                && CALCULATE ( SUM ( 'BD'[Movidas] ), 'BD'[Transporte] = "FFCC" ) > 0,
            ROUND (
                (
                    CALCULATE ( [$ / Ton], 'BD'[Transporte] = "Auto" )
                        - CALCULATE ( [$ / Ton], 'BD'[Transporte] = "FFCC" )
                )
                    * CALCULATE ( SUM ( 'BD'[Movidas] ), 'BD'[Transporte] = "Auto" ),
                0
            ),
            0
        )
    )
    
    • AquilaVictrix's avatar
      AquilaVictrix
      Regular Visitor

      Thanks for the response! Jihwan_Kim i used the provided DAX unfortunately,  its showing still the wrong Sum at the total:

       

       



      • AquilaVictrix's avatar
        AquilaVictrix
        Regular Visitor

        *update* 

        its Weird i have another table with Key Routes thata are conected to the Main BD

        and with this the total is correct:

        Impacto = 

        SUMX(

            VALUES(Rutas[Key]),

            VAR VolumenAuto = CALCULATE(SUM(BD[Movidas]), BD[Transporte] = "Auto")

            VAR VolumenFFCC = CALCULATE(SUM(BD[Movidas]), BD[Transporte] = "FFCC")

            VAR CostoPorTonAuto = CALCULATE([$ / Ton], BD[Transporte] = "Auto")

            VAR CostoPorTonFFCC = CALCULATE([$ / Ton], BD[Transporte] = "FFCC")

            RETURN

                IF(VolumenAuto > 0 && VolumenFFCC > 0,

                    ROUND((CostoPorTonAuto - CostoPorTonFFCC) * VolumenAuto, 0),

                    0

                )

        )