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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Jitmondo
Helper III
Helper III

Sum of Margin where there are multiple line items not working

Hi

 

I have a table where I am trying to sum up margin at a unique level.

 

The table has unique sales ids but can have multiple products so has duplicate lines.The problem here is that the margin is locked at a sale id level so is duplicated, I need the margin for each product but I end up getting duplicate values included in my sum!

 

I have used 

Distinct Margin = (SUMX(DISTINCT(Opportunity[Id]), FIRSTNONBLANK(Opportunity[Margin Conversion], 0)))
 
which is almost there however if a sale id has multiple products it is not included in the calculation.

Made Up IDMarginPriceProduct
12454510300A
12454510200B
12454510100C
    
Result nowDesired Result
ProductMarginProductMargin
A13530A4510
Any ideas on where I am going wrong ?
 
thanks
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Jitmondo , Try measure like

Distinct Margin = SUMX(values(Opportunity[Id]), FIRSTNONBLANKVALUE(Opportunity[Made Up ID], sum(Opportunity[Margin Conversion])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
Jitmondo
Helper III
Helper III

Turns out my formula was correct and I had double counted (facepalm), however your formula worked!!! thanks again 🙂

amitchandak
Super User
Super User

@Jitmondo , Try measure like

Distinct Margin = SUMX(values(Opportunity[Id]), FIRSTNONBLANKVALUE(Opportunity[Made Up ID], sum(Opportunity[Margin Conversion])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for coming back to me, unfortunately it didnt work, that formula allows one of the product categories (the one I mentioned having duplicates) to double count. Not sure why its doing that unless there is something else I have missed.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors