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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Shalin
Frequent Visitor

Calculating margin % by product group

We have a Dynamics 365 database feeding into BI, which has sales invoice lines and COG's for all of the items we sell. Each item falls into a different product group, and I would like to calculate margin by product group. At a line level it's easy enough to have a column as follows:

Margin = IF(SalesInvoiceLineMargin[LINEAMOUNTMST]=0,0,(SalesInvoiceLineMargin[LINEAMOUNTMST])-(SalesInvoiceLineMargin[CAPCOSTVALUE]))/(SalesInvoiceLineMargin[LINEAMOUNTMST])
 
Where the IF function removes the errors thrownup by 0 sales price invoices. The rest of the formula is a simple margin calculation taking sales lines less COGS and divide by sales lines. For an individual item or invoice, this works fine.
 
However when I try and analyse by product group, I use the same formula and have a table with product group and then this column next, Because it is summarising the column, by default it wants to use the average of the margin per line. That is not the correct number however, because the average of all margins across all lines does not equal the weighted average of all margins. Especially when you have 0% or 100% margin lines skewing the numbers. Onedrive link to an excel file explaining the difference:
 
My question is, is there a way to get around this? Or do I need to have a much more complicated calculation column which is saying sum sales lines for this product group, less COGS for the product group, divide by sales for the product group. And then do one of those for each product group?
Ideally I would want the final margin column to be a calcuation based on the cell in the table on the visualisation. Not on the entire underlying table. So the last column is literally the equivalent of (Cell A1-Cell B1/Cell A1)
 
Thanks
2 REPLIES 2
parry2k
Super User
Super User

@Shalin hey so you are looking for result in E11 and E12, correct?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Yes looking for E11/E12 rather than B15/B16 which is what BI is currently showing

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors