Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello!
I am trying to group the top 3 stores for a metric by their district in the same pivot table. Example below...
I would like to show the top 3 in each district. Any help is appreciated!!!
Solved! Go to Solution.
TOP_N =
VAR __topn =
TOPN(
MAX( N[Value] ),
CALCULATETABLE(
SUMMARIZE( Data, Data[District], Data[Store] ),
ALLSELECTED( Data[Store] )
),
[Total]
)
RETURN
CALCULATE( [Total], KEEPFILTERS( __topn ) )
| Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
TOP_N =
VAR __topn =
TOPN(
MAX( N[Value] ),
CALCULATETABLE(
SUMMARIZE( Data, Data[District], Data[Store] ),
ALLSELECTED( Data[Store] )
),
[Total]
)
RETURN
CALCULATE( [Total], KEEPFILTERS( __topn ) )
| Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Hi,
In case you want to create a table, please check the below picture and the attached pbix file.
I tried to create a sample pbix file like below.
Top three per district table =
VAR _topthreestorelist =
SUMMARIZE (
GENERATE (
VALUES ( Data[District] ),
SUMMARIZE (
TOPN (
3,
FILTER ( Data, Data[District] = EARLIER ( Data[District] ) ),
Data[Sales], DESC
),
Data[Store]
)
),
Data[Store]
)
RETURN
CALCULATETABLE ( Data, Data[Store] IN _topthreestorelist )
Create a helper measure that will return 1 for any top 3 stores in any of the districts and then filter the visual by this value on this very measure. This will then hide the other stores and you'll only see what you want.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 13 | |
| 5 | |
| 5 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 25 | |
| 10 | |
| 10 | |
| 6 | |
| 6 |