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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ktt777
Helper V
Helper V

Formula to calculate number of contribution to percentage to total

Hi all,

 

i have a data contain spend per company in different countries. 

How do i write a dax formula to calculate number of top high spending company that contribute to 50% of total spend in each country?

 

Here is link to data example Percentage.xlsx

 

thanks, 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ktt777 , hello Ashish_Mathur and elitesmitpatel, thank you for your prompt reply!

In order to calculate the number of high-expenditure companies that account for 50 per cent of total expenditures in each country, please try as following:

 

  • Create a measure to get the CumulativePercentage for different countries:
CumulativePercentage = 
VAR CurrentCountry = MAX('Table'[Country]) 
VAR CurrentTotalSpend = MAX('Table'[TotalSpend]) 
VAR TotalSpendByCountry = CALCULATE(SUM('Table'[TotalSpend]), ALLEXCEPT('Table', 'Table'[Country])) 
VAR RunningTotal = CALCULATE(
   SUM('Table'[TotalSpend]),
   FILTER(
       ALLEXCEPT('Table', 'Table'[Country]), 
       'Table'[TotalSpend] >= CurrentTotalSpend 
   )
)
RETURN
DIVIDE(RunningTotal, TotalSpendByCountry, 0) 
  • Then create a rownumber measure to get the closest percentage to 50%
RowNumber = RANKX(ALLEXCEPT('Table','Table'[Country]),ABS([CumulativePercentage]-0.5),,ASC)
  • Lastly, create two measures you need:
Total = CALCULATE('Table'[CumulativePercentage],FILTER('Table','Table'[RowNumber]=1))
No of supplier = 

VAR CurrentCountry = MAX('Table'[Country]) 

RETURN

IF(

    [RowNumber] = 1, 

    RANKX(

        FILTER(

            ALL('Table'), 

            'Table'[Country] = CurrentCountry 

        ),

        'Table'[Percentage], 

        ,

        DESC, 

        DENSE 

    ),

    BLANK() 

)
 

 Result for your reference:

vyajiewanmsft_1-1726732733312.png

Best regards,

Joyce

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

9 REPLIES 9
Anonymous
Not applicable

Hi @ktt777 , hello Ashish_Mathur and elitesmitpatel, thank you for your prompt reply!

In order to calculate the number of high-expenditure companies that account for 50 per cent of total expenditures in each country, please try as following:

 

  • Create a measure to get the CumulativePercentage for different countries:
CumulativePercentage = 
VAR CurrentCountry = MAX('Table'[Country]) 
VAR CurrentTotalSpend = MAX('Table'[TotalSpend]) 
VAR TotalSpendByCountry = CALCULATE(SUM('Table'[TotalSpend]), ALLEXCEPT('Table', 'Table'[Country])) 
VAR RunningTotal = CALCULATE(
   SUM('Table'[TotalSpend]),
   FILTER(
       ALLEXCEPT('Table', 'Table'[Country]), 
       'Table'[TotalSpend] >= CurrentTotalSpend 
   )
)
RETURN
DIVIDE(RunningTotal, TotalSpendByCountry, 0) 
  • Then create a rownumber measure to get the closest percentage to 50%
RowNumber = RANKX(ALLEXCEPT('Table','Table'[Country]),ABS([CumulativePercentage]-0.5),,ASC)
  • Lastly, create two measures you need:
Total = CALCULATE('Table'[CumulativePercentage],FILTER('Table','Table'[RowNumber]=1))
No of supplier = 

VAR CurrentCountry = MAX('Table'[Country]) 

RETURN

IF(

    [RowNumber] = 1, 

    RANKX(

        FILTER(

            ALL('Table'), 

            'Table'[Country] = CurrentCountry 

        ),

        'Table'[Percentage], 

        ,

        DESC, 

        DENSE 

    ),

    BLANK() 

)
 

 Result for your reference:

vyajiewanmsft_1-1726732733312.png

Best regards,

Joyce

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

ktt777
Helper V
Helper V

hi, 

i updated example with expected results. Percentage.xlsx

Ashish_Mathur
Super User
Super User

Hi,

In another tab of that file, show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

sorry i did not find the 2nd tab

That is not what i asked for.  Create another tab and show the expected result there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ktt777
Helper V
Helper V

thank you. 

what i can to see is for example below. there are 11 companies at the top contribute to 50% of total spend. 

How to create formula to count to get 11 companies? There maybe can not find the exact 50% to total spend, but the closest to 50%

 

ktt777_0-1726181929132.png

 

Hi,

I have solved a similar problem in the attached PBI file.

Hope this helps.

Ashish_Mathur_0-1726278413213.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I have solved it please check the below file. 
Percentage _solved 

elitesmitpatel_0-1726285368108.png

 


Please appreciate my work if it helps you.

elitesmitpatel
Super User
Super User

Hi @ktt777 

elitesmitpatel_0-1726159828185.png

use this dax:
 C2/ SUM($C$2:$C$38)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.