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
elac
Frequent Visitor

How to calculate percentage of data selected by country

Hi there,

I have two tables

device_lookup(device name, model, country)

n1, a, US

n2, a, US

n3, b, US

n4, a, UK

 

deviceType_lookup(model, manufacturer)

a, lenovo

b, dell

c, acer

 

with slice to select the mode, how to caculate the percentage of selected devices by country.

 

ie. if user selected mode = a, i would like to get 

US, 66.66%

UK, 100%

 

Thank you in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @elac ,

 

I create a file for your reference.

The measure I used:

percentage = var _count1=CALCULATE(COUNT('device_lookup'[model]),FILTER(ALLSELECTED(device_lookup),[country]=MAX('device_lookup'[country])))
 var _count2=CALCULATE(COUNT('device_lookup'[country]),FILTER(ALL(device_lookup),[country]=MAX('device_lookup'[country])))
 return DIVIDE(_count1,_count2)

vstephenmsft_0-1681891541362.png

 

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
elac
Frequent Visitor

Hello  amitchandak,

 

First, thank you so much for answer.

 

I tried both measures but it didn't give me the expected result.

device% = divide(countrows(device_lookup), calculate(countrows(device_lookup), removefilters(deviceType_lookup[model]) ) )

device%_2 = divide(countrows(device_lookup), calculate(countrows(device_lookup), all() ) )

 

However, neither was giving the correct answer. 

method 1 always return 100%

method 2 doesn't group on country, it acutally get the percentage on all devices in device lookup

 

elac_1-1680730266428.png

 

Any thoughts? Any help is appreciated!

 

Elac

Anonymous
Not applicable

Hi @elac ,

 

I create a file for your reference.

The measure I used:

percentage = var _count1=CALCULATE(COUNT('device_lookup'[model]),FILTER(ALLSELECTED(device_lookup),[country]=MAX('device_lookup'[country])))
 var _count2=CALCULATE(COUNT('device_lookup'[country]),FILTER(ALL(device_lookup),[country]=MAX('device_lookup'[country])))
 return DIVIDE(_count1,_count2)

vstephenmsft_0-1681891541362.png

 

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

Hello Stephen,

This is terrific. It solves my problem perfectly.

If you don't mind, could you tell what is wrong with my original measure?

device%= divide(countrows(device_lookup), calculate(countrows(device_lookup), removefilters(deviceType_lookup[model]) ) )

 

Thank you so much!

Elac

amitchandak
Super User
Super User

@elac , Try a measure like

 

divide(countrows(Table), calculate(countrows(Table), removefilters(deviceType_lookup[model]) ) )

 

or

 

divide(countrows(Table), calculate(countrows(Table), all() ) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.