Forum Discussion
Calculating percentage based on multiple top N parameters
- 9 years ago
Hi manish2k
Try creating a calculated table that summarises the data using this code
Summary Table = SUMMARIZE( 'Table1', Table1[Supplier Name], 'Table1'[Category] , "Total Spend",SUM('Table1'[Spend]) )Then add the following calculated column to this newly created table
Supplier Category Rank = CALCULATE( COUNTROWS('Summary Table'), FILTER('Summary Table', 'Summary Table'[Category] = EARLIER('Summary Table'[Category]) && 'Summary Table'[Total Spend] >= EARLIER('Summary Table'[Total Spend] ) ) )+0Finally create the following measure
Top 3 Suppliers contribution to overall cat spend =
VAR TopNValue = 3
VAR Top3Spend = CALCULATE(
SUM('Summary Table'[Total Spend]),
FILTER(
ALLEXCEPT('Summary Table','Summary Table'[Category]),
'Summary Table'[Supplier Category Rank]<=TopNValue)
)
VAR TotalSpend = CALCULATE(SUM('Summary Table'[Total Spend]),ALLEXCEPT('Summary Table','Summary Table'[Category]))
RETURN DIVIDE(Top3Spend,TotalSpend)and format the measure to be a percentage. I think this might be close :)
If it's close, just clone the final measure 2 times for the other TopN values
Hi manish2k
Try creating a calculated table that summarises the data using this code
Summary Table = SUMMARIZE(
'Table1',
Table1[Supplier Name],
'Table1'[Category] ,
"Total Spend",SUM('Table1'[Spend])
) Then add the following calculated column to this newly created table
Supplier Category Rank =
CALCULATE(
COUNTROWS('Summary Table'),
FILTER('Summary Table',
'Summary Table'[Category] = EARLIER('Summary Table'[Category])
&& 'Summary Table'[Total Spend] >= EARLIER('Summary Table'[Total Spend]
)
)
)+0Finally create the following measure
Top 3 Suppliers contribution to overall cat spend =
VAR TopNValue = 3
VAR Top3Spend = CALCULATE(
SUM('Summary Table'[Total Spend]),
FILTER(
ALLEXCEPT('Summary Table','Summary Table'[Category]),
'Summary Table'[Supplier Category Rank]<=TopNValue)
)
VAR TotalSpend = CALCULATE(SUM('Summary Table'[Total Spend]),ALLEXCEPT('Summary Table','Summary Table'[Category]))
RETURN DIVIDE(Top3Spend,TotalSpend)
and format the measure to be a percentage. I think this might be close :)
If it's close, just clone the final measure 2 times for the other TopN values
- manish2k9 years agoRegular Visitor
Awesome ! This worked ! Thanks a million !
- manish2k8 years agoRegular Visitor
Phil_Seamark I have one change to ask , what if the main summary table gets one more filer . Let say a department . How will i be able to incorporate it into the below code?