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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Morran
Helper I
Helper I

Using Calculate to see Grand Average of Top N

Dear People,

I hope you're doing well. I'd like to ask about DAX tips to you. I have a case to figure out Grand Average of several items within specific rank. 
The following image is a list of all items that I sorted based on their Average values. As you can see, Ethiopia has the highest Average value and followed by the other countries. The grand average of all items is 81.95 
Grand Average of all itemsGrand Average of all items
However, I'd like to find out the Grand Average value of items that are outside Top 3. I created a measure in order to make me easy to adjust N value (It could be 4, 5, 10, etc. But in this case let's assume the N has a fixed value). The DAX is shown in the image below as follows:
DAX with fixed N value of 3DAX with fixed N value of 3
After applying this measure, instead of getting different value, I got the exact same Grand Average value of all items. 
Grand Average of items outside Top 3Grand Average of items outside Top 3
I compare the Grand Average of "Outside Top N" using DAX with the Grand Average of "Outside Top N" using visual filter. You can see the images as follows:
Grand Average of Outside Top N using Visual FilterGrand Average of Outside Top N using Visual FilterFilter out Top 3 itemsFilter out Top 3 items
As you can see the Grand Average is 81.80 by excluding Top 3 items (Ethiopia, Papua New Guinea, and United States). This is my expected result. 
In short, I want to create a measure to obtain a Grand Average of items beyond top 3 that rules out top 3 items. Could you please help me to figure out the bug in my DAX? Thank you.

Regards

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Morran , Try a measure like

if(isninscope('Table'[Country]), [Avg TCP] ,
AverageX(keepfilters(topn(10, ALLselected('Table'[Country]) , [Avg TCP])), [Avg TCP])
)

 

you can use TOPN or window

TOPN: https://youtu.be/QIVEFp-QiOk
TOPN with Numeric Parameter -https://youtu.be/cN8AO3_vmlY?t=26448

 

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Morran , Try a measure like

if(isninscope('Table'[Country]), [Avg TCP] ,
AverageX(keepfilters(topn(10, ALLselected('Table'[Country]) , [Avg TCP])), [Avg TCP])
)

 

you can use TOPN or window

TOPN: https://youtu.be/QIVEFp-QiOk
TOPN with Numeric Parameter -https://youtu.be/cN8AO3_vmlY?t=26448

 

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak , Thanks for your response. Let me try and get back to you. Thanks.

Regards

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.