Forum Discussion
DAX calculation help!
- Anonymous2 years ago
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.
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.
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.
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.
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.
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.