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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply

Need help calculating percentage of an individual value within its group (Power BI, DAX)

Hi DAX gurus,

I need help writing a measure. The sample data is as shown below:-

Sample Data.png

 

I wish to find the percentage of each country within the group "International" every year.

For example, India in year 2020 = 50%; USA in year 2020 = 50%. India in year 2021 = 100%. Etc.

This is what I have written, however, this doesn't work:-

DIVIDE (
        COUNT ( 'Data'[Country] ),
        COUNTROWS( FILTER ('Data',  'Data'[Country (group)] = "International") )
)

I believe the denominator is correct. I think the numerator needs some help.

Many thanks,
Sarthak
 
 
1 ACCEPTED SOLUTION

Hi @SachinNandanwar,

Thank you so very much for your response!

This isn't completely the correct response, however, I was able to write it with your help:-

% of Country in International =
var intl_country_every_year = CALCULATE (
    COUNT('Data'[country_description]),
    FILTER (
        ALLEXCEPT('Data', 'Data'[academic_year]),
        'Data'[country_description (groups)] = "International"
        )
)
return DIVIDE(COUNT('Data'[country_description]), intl_country_every_year)

View solution in original post

8 REPLIES 8
SachinNandanwar
Super User
Super User

This ?

Country_Percentage_International =
VAR _GroupCount =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Year] ),
            'Table'[Group] = "International"
        )
    )
RETURN
    DIVIDE (
        COUNTROWS (
            FILTER (
                SUMMARIZE ( 'Table', 'Table'[StudentId], 'Table'[Group] ),
                'Table'[Group] = "International"
            )
        ),
        _GroupCount,
        0
    ) * 100


this the data

StudentId,Country,Group,Year
1,India,Domestic,2020
2,USA,International,2021
3,Canada,International,2022
4,India,Domestic,2023
5,USA,International,2020
6,Canada,International,2021
7,India,Domestic,2022
8,USA,International,2023
9,Canada,International,2020
10,India,International,2021
11,USA,International,2021

SachinNandanwar_0-1727115948620.png

 



Regards,
Sachin
Check out my Blog

Hi @SachinNandanwar,

Thank you so very much for your response!

This isn't completely the correct response, however, I was able to write it with your help:-

% of Country in International =
var intl_country_every_year = CALCULATE (
    COUNT('Data'[country_description]),
    FILTER (
        ALLEXCEPT('Data', 'Data'[academic_year]),
        'Data'[country_description (groups)] = "International"
        )
)
return DIVIDE(COUNT('Data'[country_description]), intl_country_every_year)
Selva-Salimi
Super User
Super User

Hi @sarthakgirdhar 

I think every row in your data play role so you just need to devide "one" by calculating the denaminator. you can write a measure as follows:

 

Measure_share := 1 /  calculate (distinctcount(country) , filter (all(your_table) , year=selectedvalue(year) && country(group) = "International")

 

If this post helps, then I would appreciate a thumbs up 👍  and mark it as the solution to help the other members find it more quickly. 

 

 

Hi @Selva-Salimi,

I tried your solution, however, it doesn't give the desired output.

Thanks a lot for your attempt though 🙂

So, let me know what was the issue and also what are the visuals you use to display this measure ( image of sample if possible)

This is what it looks like:-

Sample Image.png

% Test3 is the measure.

@sarthakgirdhar 

 

Are they the only international countries in 2020? is the column academic_year used in selectedvalue function in measure?!

There are about 100 International countries every year. The years go from 2020 to 2024.

I wrote the measure as per your post:-

% Test3 = 1 /  CALCULATE(
    distinctcount('Data'[country_description]) , filter (all('Data') , selectedvalue('Data'[academic_year]) && 'Data'[country_description (groups)] = "International")
)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.