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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Wanderer1985
New Member

Top 3 Value for each category and year

Hi im trying to create a Top 3 measure (rank) for each Year and Area. Is it possible to create a measure that rank the value based on dimension value area and year like:

Wanderer1985_0-1644840183415.png

 

I have already tried this post, and cant get it to work in my scenario:

 

https://www.sqlbi.com/articles/filtering-the-top-3-products-for-each-category-in-power-bi/

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Wanderer1985 ,

Here are the steps you can follow:

1. Create measure.

rank =
RANKX(
    FILTER(ALL('Table'),'Table'[Area]=MAX('Table'[Area])&&'Table'[Year]=MAX('Table'[Year])),
    CALCULATE(SUM('Table'[Value])),,DESC)

2. Result:

vyangliumsft_0-1645149464922.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

7 REPLIES 7
Anonymous
Not applicable

Did You Try This Measure? 
Rank within Area =

      
RANKX (
ALLEXCEPT ( Table1, Table1[Area] ),
CALCULATE ( SUM ( Table1[Value] ) )
)

v-yangliu-msft
Community Support
Community Support

Hi  @Wanderer1985 ,

Here are the steps you can follow:

1. Create measure.

rank =
RANKX(
    FILTER(ALL('Table'),'Table'[Area]=MAX('Table'[Area])&&'Table'[Year]=MAX('Table'[Year])),
    CALCULATE(SUM('Table'[Value])),,DESC)

2. Result:

vyangliumsft_0-1645149464922.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

Anonymous
Not applicable

Hi, @Wanderer1985  Please Try This Measure.

Rankx =
RANKX (
FILTER (
ALL ( 'Table '[Area], 'Table '[Year] ),
'Table'[Area] = MAX ( 'Table'[Area] )
),
CALCULATE ( SUM ( 'Table'[Value] ) )
)



Hi, this also only gives 1 in return... 

 

Wanderer1985_0-1644846242069.png

 

Wanderer1985_1-1644846262184.png

 

 

Anonymous
Not applicable

ok, Try This Measure.

 

Rank within Area =
RANKX (
    ALLEXCEPT ( Table1, Table1[Area] ),
    CALCULATE ( SUM ( Table1[Value] ) )
)

 

I Try This Measure in your file and it's working. if your got a solution please mark this as a solution

amitchandak
Super User
Super User

@Wanderer1985 , Create a simple TOP 3 and use that

 

Top 3= calculate(max(Table[Year]),TOPN(3,allselected(table[Year]),calculate(sum(Table[Value])),DESC), values(table[Year]))

 

or create a rank measure and filter at visual level for <=3
Rankx(allselected(table[Year]), calculate(sum(Table[Value])),,desc)

or


Rankx(filter(summarize(allselected(table),Table[Year], table[Area]), [Area] =max([Area])), calculate(sum(Table[Value])),,desc)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi amitchandak.

 

I have tried all 3 solutions now - and do not get the expected result:

Wanderer1985_2-1644843644036.png

 

I have added the PBIX file with the example if you would like to have a look at the scenario 🙂

 

top 3 ex 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.