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
cmcgo3
Helper II
Helper II

Need a Dax Measure -Help !!

Lets say I had 200 students with a list of average scores from 0 to 100.   There are also two filters, a date filter by week and a second filter for location of student.  There was also a condition created that put those average scores in two categories; "high and medium" 35 to 100 and "low" below 35.  The students and average scores vary week to week.

Lets say that the following table in PowerBI displays that 140 of those 200 students with their average score in the "high / medium" category for a particular week.

How do I write a measure that will produce only 10% of those names in the "high/medium" category for an output of 14?

I have been trying to find something in the TopN function.  Most posts I see are for calculating percentages of columns which is not what I am looking for.  I have been researching for over a week and cannot come up with anything.

 

Any help is appreciated!!!

Best,

Chris C.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @cmcgo3 , 

I created some data:

vyangliumsft_0-1685337672756.png

 

Here are the steps you can follow: 

1. Create measure. 

Flag = 
var _count=COUNTX(ALLSELECTED('Table'),'Table'[StudentID]) 
var _per=_count*0.1 
var _rank=RANKX(ALLSELECTED('Table'),CALCULATE(SUM('Table'[average scores])),,DESC) 
return 
IF( 
    _rank<=_per,1,0) 

2. Place [Flag]in Filters, set is=1, apply filter. 

vyangliumsft_1-1685337672757.png

3. Result: 

vyangliumsft_2-1685337779195.png

 

Best Regards, 

Liu Yang 

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

5 REPLIES 5
cmcgo3
Helper II
Helper II

cmcgo3_0-1692663842823.png

I also wanted to add a table underneath that would give you totals.  For this example, Total Students 20, Count of automobile I would want 3 and then percentage of total ...20 students / 3 chevrolet .15 or 15%.  Any help would be greatly appreciated !!

cmcgo3
Helper II
Helper II

I am trying to add another feature; having some challenges with creating a measure....

 

cmcgo3_0-1692654356938.png

 

 

Flag =
var _count=COUNTX(ALLSELECTED('Scores'),'Scores'[name])
var _per=_count*0.30
var _rank=RANKX(ALLSELECTED('Scores'),CALCULATE(SUM('Scores'[score])),,DESC)
return
IF(
    _rank<=_per,1,0)
 
Total Students = COUNTROWS(FILTER('Scores','Scores'[Flag]=1))
 The output for total students is 20; which is correct.
How would I write a measure that would capture what type of automobile a student drives based on the filtered total of 20.  For example, of those 20 students, 3 students have "Chevrolet" as automobile.  What measure would you write to get a total of 3?
 
I have been "stuck" on trying to create this calculation.
 
Best Regards,
 
Chris C.
cmcgo3
Helper II
Helper II

I am trying to add another feature; having some challenges with creating a measure....

 

cmcgo3_1-1692652325548.png

 

Flag =
var _count=COUNTX(ALLSELECTED('Scores'),'Scores'[name])
var _per=_count*0.30
var _rank=RANKX(ALLSELECTED('Scores'),CALCULATE(SUM('Scores'[score])),,DESC)
return
IF(
    _rank<=_per,1,0)
 
Total Students = COUNTROWS(FILTER('Scores','Scores'[Flag]=1))
 The output for total students is 20; which is correct.
How would I write a measure that would capture what type of automobile a student drives based on the filtered total of 20.  For example, of those 20 students, 3 students have "Chevrolet" as automobile.  What measure would you write to get a total of 3?
 
I have been "stuck" on trying to create this calculation.
 
Best Regards,
 
Chris C.
Anonymous
Not applicable

Hi  @cmcgo3 , 

I created some data:

vyangliumsft_0-1685337672756.png

 

Here are the steps you can follow: 

1. Create measure. 

Flag = 
var _count=COUNTX(ALLSELECTED('Table'),'Table'[StudentID]) 
var _per=_count*0.1 
var _rank=RANKX(ALLSELECTED('Table'),CALCULATE(SUM('Table'[average scores])),,DESC) 
return 
IF( 
    _rank<=_per,1,0) 

2. Place [Flag]in Filters, set is=1, apply filter. 

vyangliumsft_1-1685337672757.png

3. Result: 

vyangliumsft_2-1685337779195.png

 

Best Regards, 

Liu Yang 

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

THANK YOU!, THANK YOU!, THANK YOU !!  It works great for me!!!!!

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.