Forum Discussion

EFI's avatar
EFI
Helper I
1 year ago
Solved

Wrong total in automatic sum

Hello there,   I have an issue with the automatic total/sum in Power Bi.   I export the table in Excel so I can actually see the difference.   The sum of the first column "Rebut à confirmer" is...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi,EFI .Thank you for your reply.
    You can't multiply sums directly because Power BI's calculation principle is that when the calculation logic is simple, the system will default to performing the same calculation logic for the Total column that it performs for each of the rows above: multiply the two SUMs that have been aggregated. Because the data in the rows above you is limited by the current row context, they each perform SUM aggregation or display itself, the two themselves after the aggregation of the multiplication does not seem to change!
    At this point, the computational environment is:

    SUM(Current line01 self)*SUM(Current line02 self)

    The calculated result is equivalent to:

    [Current line01]*[Current line02]
    like this:
    SUM(2)*SUM(5)=2*5=10

    But for the Total row, which doesn't exist by itself and is an aggregate value, it performs the above calculation logic by default
    It directly multiplies the two totals of the SUM function already executed, which gives the “wrong result”.

    The right way to do it.
    In this case, use SUMX('Table'[column1]*'Table'[column2]).

    If two fields do not belong to the same table, but there is a relationship between them (not a many-to-many relationship), they can be related using the related function


    Buy for your data :

    Although there is a relationship between these two tables, but the relationship is many-to-many, so you can not use the related function

    A better approach is to use the SUMMARIZE and SUMX functions to calculate the sum (for a many-to-many relationship between two tables)

    Your two tables, Prix_MAT1 and 'Production, and they are related via Prix Actuel, then the final correct DAX code is as follows:

    The steps for this formula are as follows:
    A better approach is to use your previously created measure to assist in the calculation via SUMX

    Prix Actuel DAX = SUMX('Prix_MAT1',Prix_MAT1[Prix Actuel])

     

    Calculate with measure[Prix Actuel DAX] with 'Production'[Rebut a confirmer] in the Production table

    M_result2 = SUMX('Production','Production'[Rebut à confirmer] * [Prix Actuel DAX])

     

    The final calculation result will be 17000 as you expected. I hope my test will be helpful to you


    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Carson Jian,
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.