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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Charcho
Helper I
Helper I

Operations SUMX table simple related

Hello, I have a beginner's question: How can I sum the values of attributes (A, B) and display the result in a new matrix for each? I created a DAX formula with SUMX, but it's not giving me the correct result. The two tables are related (1-*) with an attribute table. Capture.JPG

1 ACCEPTED SOLUTION
Charcho
Helper I
Helper I

@Ashish_Mathur @rajendraongole1 @Deku solved my issue! Here's the link with the solution.

https://www.dropbox.com/scl/fo/9qzy7t1nti2hgt0b2bsnr/AOXdgYX-n0wpPpMvDubjmVk?rlkey=z9g1t839bvk569oyx...

I created two dimension tables (Fruit and Attribute) and established a relationship between them. The code I needed was. What do you think? Thank you

Difference_Table2_Table1 =
VAR SelectedAttribute = SELECTEDVALUE(Table1[Attribute], "None")
VAR T_table2 =
    SUMX(
        FILTER(
            Table2,
            Table2[Attribute] = SelectedAttribute || SelectedAttribute = "None"
        ),
        Table2[Value]
    )
VAR T_table1 =
    SUMX(
        FILTER(
            Table1,
            Table1[Attribute] = SelectedAttribute || SelectedAttribute = "None"
        ),
        Table1[Value]
    )
RETURN
    T_table2 - T_table1

View solution in original post

6 REPLIES 6
Charcho
Helper I
Helper I

@Ashish_Mathur @rajendraongole1 @Deku solved my issue! Here's the link with the solution.

https://www.dropbox.com/scl/fo/9qzy7t1nti2hgt0b2bsnr/AOXdgYX-n0wpPpMvDubjmVk?rlkey=z9g1t839bvk569oyx...

I created two dimension tables (Fruit and Attribute) and established a relationship between them. The code I needed was. What do you think? Thank you

Difference_Table2_Table1 =
VAR SelectedAttribute = SELECTEDVALUE(Table1[Attribute], "None")
VAR T_table2 =
    SUMX(
        FILTER(
            Table2,
            Table2[Attribute] = SelectedAttribute || SelectedAttribute = "None"
        ),
        Table2[Value]
    )
VAR T_table1 =
    SUMX(
        FILTER(
            Table1,
            Table1[Attribute] = SelectedAttribute || SelectedAttribute = "None"
        ),
        Table1[Value]
    )
RETURN
    T_table2 - T_table1
Charcho
Helper I
Helper I
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Charcho
Helper I
Helper I

@rajendraongole1The code isn't working as expected. Could you review it? I might be missing something: 

Difference_A =
SUMX(
    VALUES(Attribute[Attribute]),
    SUM(Table2[Value]) - SUM(Table1[Value])
)
rajendraongole1
Super User
Super User

Hi @Charcho  - For each attribute, you can create a measure that calculates the difference between the two tables.

rajendraongole1_0-1741277075920.png

 

Difference A =
SUMX(
VALUES(AttributeTable[Fruit]),
SUM(Table1[A]) - SUM(Table2[A])
)

Difference B =
SUMX(
VALUES(AttributeTable[Fruit]),
SUM(Table1[B]) - SUM(Table2[B])
)

Difference Total =
SUMX(
VALUES(AttributeTable[Fruit]),
SUM(Table1[Total]) - SUM(Table2[Total])
)

replace with your table name as per your model. Hope it works. please check.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Deku
Super User
Super User

I would suggest first pivoting the data so that A and B are values in a single Category column. Then you put the Category column as a column header in your matrix and use a simple measure 

 

Sum( tbl[value])


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.