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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
MNGoodyear
Frequent Visitor

Calculations

HI,

 

I am sure this will be simple but very annoying.

 

I have cretaed a very simple example to demonstrate my frustration/inability

 

In the below table I have created the margin column and the total margin column using DAX formula

 

if you take total margin i have created a formula as follows:

Total Margin =
(SUM('Report 1'[Price]) - SUM('Report 1'[Cost])) * SUM('Report 1'[Qty])

 

This works when dispalying the data in a table , but the totals dont work  and similarily it wouldn't work if i wanted to display the value in a "Card" , as the context of the "product" has been lost.

 

In the example the total for "Total Margin" should be 2480, not 9900

 

I apprciate this is because i am using "Sum" in the calulation but cannot see any other way.

 

In other tools you can apply context by saying somthing like:

 (SUM('Report 1'[Price]) - SUM('Report 1'[Cost])) * SUM('Report 1'[Qty]) in ('Report 1'[Product])

 

Product priceCostmarginqtyTotal Margin
a10080205100
b50401010100
c302821530
d20015050201000
e15010050251250
Totals530398132759900

 

 

Is there a simple way to achieve this

 

Thanks

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@MNGoodyear

 

Use this MEASURE instead.

 

Hopefully this will work for both table and card visual

 

Total MArgin = SUMX('Report 1',([price]-[Cost])*[qty])

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@MNGoodyear

 

Use this MEASURE instead.

 

Hopefully this will work for both table and card visual

 

Total MArgin = SUMX('Report 1',([price]-[Cost])*[qty])

Thanks very much

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.