How would you use correct measures/calculated fields to define gross margin percentage in DAX?

To define the measure for the gross margin percentage at a grand total level, It is really important to understand that the sum of the percentages (created by using the current row context) can not give you the correct number for the grand total. In order to create a measure for the grand total cell, The first step required is to create the gross margin calculated column in the FactSales table. This can be achieved by 

FactSales [ Gross Margin] = Factsales[SalesAmount] - FactSales[ ProductCost]

This shows the power of Row Context in the Calculated Column which is computed during the data model processing and consumes the Valuable RAM and can significantly slow down the performance of the data model if not used in a correct way ( In case of using large number of Iterator functions such as SUMX, FILTER etc.)

Taking a wrong turn on DAX slippery slope is pretty common as an inexperienced user and require analytical sense to understand the underlying mechanics. If you sum up the Gross margin percentages at row level in a new calculated column by dividing gross margin column with Sales Amount column,  it will give you the correct percentages at row level which can be used either as a slicer or input to a any other measure calculation but not at a grand total level.

The Gross margin Percentage Measure can be calculated by

1. Creating Total Gross Margin Measure

FactSales[Total Gross Margin] := SUM(FactSales[Gross Margin])

2. Creating Total Sales Measure

FactSales[Total Sales] := SUM(FactSales[Sales Amount])

3. Taking a Ratio of 1 and 2

FactSales[Gross Margin %]:=DIVIDE(FactSales[Total Gross Margin],FactSales[Total Sales])

This newly developed measure can be evaluated in pivot table against the available contexts. 

 

Please feel free to ask questions.

Boom Boom PowerBI ...................

 

 

 

 

 

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics