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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
yzornetta
New Member

Incorrect Totals even with SUMX!

Hi All!

Like many others, I'm experiencing issues with Totals in a Matrix. Despite trying various solutions involving SUMX and SUMMARIZE, I couldn’t solve it so far.

I've attached a file with sample data for your reference.

 

yzornetta_0-1738337078413.png

 

To calculate Total Revenue, I need to multiply a fixed rate (specific to each Branch and Fiscal Year) by the total units sold. The rate value is stored in a static table (F0902) that is not directly related to my data model. Therefore, I use the TREATAS function to establish the necessary relationships.

 

Total Revenue =

VAR rate_x_meter =

    CALCULATE(

    SUM(F0902'[Rate per meter]),

    TREATAS(VALUES(F1201'[ResponsibleBU]), F0902'[BusinessUnit]),

    TREATAS(VALUES(F1202-F0911'[FiscalYear]), F0902'[FiscalYear])

)

RETURN

rate_x_meter * [Units Sold]

 

My units are calculated in a separate measure, which aggregates all units sold based on a specified Period parameter.

 

Units Sold =

        CALCULATE(

            SWITCH( 'Period'[Period Value],

                    1, SUM(F1202-F0911'[Period01Balance]),

2, SUM(F1202-F0911'[Period01Balance]) + SUM(F1202-F0911'[Period02Balance]),

3, SUM(F1202-F0911'[Period01Balance]) + SUM(F1202-F0911'[Period02Balance]) + SUM(F1202-F0911'[Period03Balance]),

            ),

            FILTER(

               F1202-F0911',

                (RELATED('ObjectAccount'[AccountNumber])= "31600"

            )

)

 

My data model:

yzornetta_1-1738337078417.png

 

All subtotals by branch are ok, but the problem is the final total as you see in my first screenshot.

Could you please help me? I’ve been trying a lot, and it is driving me crazy.

 

Thanks!

 

1 ACCEPTED SOLUTION

@yzornetta - Sorry for the delay. 

 

The suggestions made here would all work, except for the fact that your Rate per meter calculation does not work at the 3 levels (Branch Description, Unit Description, Total) when calculated inside the Total Revenue measure, hence why this does not all correctly aggregate at the total level. It therefore needs to be calculated in a separate measure, and then referenced in this measure. 

 

This means the Total Revenue measure (according to your sample data) you need to use is:

 

 

VAR _table =
    SUMMARIZECOLUMNS (
        'PRODCTL F0005 (Branch)'[Description],
        'PRODDTA F1201'[Unit - Description]
    )
RETURN
    IF (
        HASONEVALUE ( 'PRODCTL F0005 (Branch)'[Description] ),
        SUMX ( _table, - ( [Rate per meter] * [Units Sold] ) ),
        SUMX (
            ALL ( 'PRODCTL F0005 (Branch)'[Description] ),
            - ( [Rate per meter] * [Units Sold] )
        )
    )

 

 

See below for expected total:

 

mark_endicott_0-1738663534766.png

 

Please accept this as the solution so others with the same challenge can find the answer. 

View solution in original post

9 REPLIES 9
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from Greg_Deckler  and mark_endicott , please allow me to add some more information:


Hi  @yzornetta ,

 

Measure follows the context of the "Total" row and is calculated in that context. Therefore, using a measure in a column of a table visualization may have unexpected values in the "Total" column.

 

You can use the IF()+HASONEVALUE() function to determine whether it is “Row subtotals” or “Row grand total”, and if it is, you can add as many columns as you want. If it is, you can add the columns that appear in the visual to do the calculation, such as the average, Sum and so on.

 

You can try the following dax and replace the table and column names that appear below with the corresponding column names that appear in visual.

Measure =
IF(
    HASONEVALUE('Table'[Description]),SUMX('Table',[Total Revenue]),
IF(
    HASONEVALUE('Table'[Branch]),SUMX(FILTER(ALL('Table'),[Branch]=MAX([Branch])),[Total Revenue]),
    SUMX(
      ALL('Table'),[Total Revenue]))
    )

 

vyangliumsft_0-1738639163515.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@yzornetta First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
mark_endicott
Super User
Super User

@yzornetta - The SUMX for the total is calculating at the Aggregate level, it will not iterate throught the rows of your table unless you tell it to. I suggest you use a pattern like this:

 

VAR _table =
    ADDCOLUMNS (
        SUMMARIZE ( 'Branch', 'Branch'[Column 1], 'Branch'[Column 2] ),
        "units", [Units Sold],
        "rate_x_meter",
            CALCULATE (
                SUM ( 'F0902'[Rate per meter] ),
                TREATAS ( VALUES ( 'F1201'[ResponsibleBU] ), 'F0902'[BusinessUnit] ),
                TREATAS ( VALUES ( 'F1202-F0911'[FiscalYear] ), 'F0902'[FiscalYear] )
            )
    )
RETURN
    SUMX ( _table, [rate_x_meter] * [units] )

 

If this works, please accept it as the solution to help others with the same challenge. 

Hello! thanks for your time, unfortunately I tried it but it is still the same:

 

yzornetta_0-1738340591820.png

 

@yzornetta You have two columns in your matrix, but only one in the SUMMARIZE, please try adding the additional column. 

Hi @mark_endicott I can not added it in the SUMMARIZE as this column is not from the Branch table, what can I do in this case?  

 

yzornetta_0-1738345342636.png

 

I updated the formula to include both columns in the SUMMARIZE, but it is still not working 😞 

yzornetta_0-1738347049656.png

 

@yzornetta - Sorry for the delay. 

 

The suggestions made here would all work, except for the fact that your Rate per meter calculation does not work at the 3 levels (Branch Description, Unit Description, Total) when calculated inside the Total Revenue measure, hence why this does not all correctly aggregate at the total level. It therefore needs to be calculated in a separate measure, and then referenced in this measure. 

 

This means the Total Revenue measure (according to your sample data) you need to use is:

 

 

VAR _table =
    SUMMARIZECOLUMNS (
        'PRODCTL F0005 (Branch)'[Description],
        'PRODDTA F1201'[Unit - Description]
    )
RETURN
    IF (
        HASONEVALUE ( 'PRODCTL F0005 (Branch)'[Description] ),
        SUMX ( _table, - ( [Rate per meter] * [Units Sold] ) ),
        SUMX (
            ALL ( 'PRODCTL F0005 (Branch)'[Description] ),
            - ( [Rate per meter] * [Units Sold] )
        )
    )

 

 

See below for expected total:

 

mark_endicott_0-1738663534766.png

 

Please accept this as the solution so others with the same challenge can find the answer. 

You are my hero!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thank you so much!! ❤️

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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