Forum Discussion
Order Level Margin % Data
Hi,Dave1mo1 I am glad to help you.
According to your description, you have successfully created a measure to calculate the profit percentage for the order level, you now need a measure to calculate the aggregated profit percentage for the whole order level on top of the original one.
As you have not given a specific data example, I have created my own simple test data that you can refer to. If my simulation of your model data fails and does not match your actual data model, please point it out and share your test pbix file that does not contain sensitive data and matches your current data format.
how to share your file.
URL:
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.powerbi.com%2Ft5%2FCommunity-Blog%2FHow-to-Get-Your-Question-Answered-Quickly%2Fba-p%2F38490&data=05%7C02%7Cv-jianpengli%40microsoft.com%7Cd9552f18a0c94a7564f308dc188bf35e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638412236574903368%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3jxUE%2BTNC8dS4DIhPphEB3NA%2BK94pwURGHu%2BXC4eezw%3D&reserved=0
Here is my test data, I hope it will be helpful to you
Assuming that there are multiple orders (different order IDs), each with a different Product, and each Product has a corresponding Sales and Margin
Here is my dax code:
Booked - Margin Percent = [Booked - Total Margin]/[Booked - Total Sales]
Total Order Margin Percent =
VAR TotalMargin = CALCULATE(SUMX('Table',[Booked - Total Margin]),FILTER(ALL('Table'),'Table'[OrderID]=MAX('Table'[OrderID])))
VAR TotalSales = CALCULATE(SUMX('Table',[Booked - Total Sales]),FILTER(ALL('Table'),'Table'[OrderID]=MAX('Table'[OrderID])))
RETURN
DIVIDE(TotalMargin, TotalSales, 0)
Booked - Margin Percent This measure calculates the percentage of each Product in each order ProductA: 20/100=20%.
Total Order Margin Percent This measure calculates the percentage of the entire order (20+50)/(100+200)=23.33%.
As a conclusion, Total Order Margin Percent calculates the percentage of the entire order based on the original measure: [Booked - Margin Percent
Group Aggregation
Note that the code I've provided will most likely not fit your real calculation environment, so you need to pay more attention to how to implement the aggregation of orders into groups to find the percentage of each order as a whole.
You need to write a measure based on your real data, I hope my suggestion will help you.
If you can, please share your test pbix file without sensitive data to show the structure of your real data model, it will help you to find the right suggestion faster.
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.