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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
mlmchilli
Frequent Visitor

DAX calculation help!

Hello!

 

I'm hoping somebody can point me in the right direction with a DAX query that I need to be able to solve but can't quite get me head around.

 

We have a fact table at a day granularity where a product has total cost and revenue metrics. I need to be able to calculate a margin share of the total cost i.e. revenue/total cost and then share the margin between two partners based on rules.

 

Partner A must get at least 20% margin.

Partner B then gets anyting over 20% margin up until 40%

The margin over 40% is shared equally by A & B

 

So, for example:

 

Product A on Jan 1 2024 has TotalCost 1000 and Revenue 300 = 30% margin

Partner A gets  200, Partner B gets 100 

 

Product B on Jan 1 2024 has TotalCost 1000 and Revenue 390 = 39% margin

Partner A gets  200, Partner B gets 190

 

Product C on Jan 1 2024 has TotalCost 1000 and Revenue 400 = 40% margin

Partner A gets  200, Partner B gets 200

 

Product D on Jan 1 2024 has TotalCost 1000 and Revenue 540 = 54% margin

Partner A gets  270, Partner B gets 270 

 

Any guidance or help on this would be very much appreciated!

 

Thanks

 

1 ACCEPTED SOLUTION
v-jiewu-msft
Community Support
Community Support

Hi @mlmchilli ,

First of all, many thanks to @lbendlin  for your very quick and effective replies, and I will give some additions below:

1.Create the sample table.

vjiewumsft_0-1713344943337.png

2.Create the new measure to calculate the margin share.

 

Margin Share = 
var partn_ = SELECTEDVALUE('Table'[Partners])
VAR Margin = DIVIDE(SUM('Table'[Revenue]), SUM('Table'[Total cost]))
VAR BaseMargin = 0.2
VAR UpperMargin = 0.4
VAR ExcessMargin = MAX(0, Margin - UpperMargin)
VAR SharedExcess = ExcessMargin / 2

RETURN
IF(partn_ = "A", 
    IF(Margin <= 0.4, BaseMargin * SUM('Table'[Total cost]), BaseMargin * SUM('Table'[Total cost]) + SharedExcess * SUM('Table'[Total cost])),
    IF(Margin <= 0.4, (Margin - BaseMargin) * SUM('Table'[Total cost]), BaseMargin * SUM('Table'[Total cost]) + SharedExcess * SUM('Table'[Total cost]))
)

 

3.Drag the measure into the table visual. The result is shown below.

vjiewumsft_1-1713344984316.png

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-jiewu-msft
Community Support
Community Support

Hi @mlmchilli ,

First of all, many thanks to @lbendlin  for your very quick and effective replies, and I will give some additions below:

1.Create the sample table.

vjiewumsft_0-1713344943337.png

2.Create the new measure to calculate the margin share.

 

Margin Share = 
var partn_ = SELECTEDVALUE('Table'[Partners])
VAR Margin = DIVIDE(SUM('Table'[Revenue]), SUM('Table'[Total cost]))
VAR BaseMargin = 0.2
VAR UpperMargin = 0.4
VAR ExcessMargin = MAX(0, Margin - UpperMargin)
VAR SharedExcess = ExcessMargin / 2

RETURN
IF(partn_ = "A", 
    IF(Margin <= 0.4, BaseMargin * SUM('Table'[Total cost]), BaseMargin * SUM('Table'[Total cost]) + SharedExcess * SUM('Table'[Total cost])),
    IF(Margin <= 0.4, (Margin - BaseMargin) * SUM('Table'[Total cost]), BaseMargin * SUM('Table'[Total cost]) + SharedExcess * SUM('Table'[Total cost]))
)

 

3.Drag the measure into the table visual. The result is shown below.

vjiewumsft_1-1713344984316.png

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Spoiler
Many thanks Wisdom! This pointed me in the right direction so much appreciated!
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors