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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors