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
Ebrahim1123
New Member

Need help with Rank function dax

I have 3 Columns:- Year, Runs, and Batsman.  I need to find a batsman who has scored the most runs year-wise.
Like for
2016- 973 - Kohli 

2017 - 641 -Warner
2018 - 735 -Williamson and so.
I know we can achieve this through the Rank function but not able to figure out how as I am new to Power BI Dax. 

Screenshot (42).png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Ebrahim1123 

 

For questions where you want to find the batsman who scores the most points per year via the rank function, we recommend that you use “rankx”, as “rankx” sorts the same values in the column to the same level. This avoids over-sieving or missing data.

 

we have the following solutions:

 

Here's some dummy data

vnuocmsft_0-1703665576404.png

 

Create a measure, after grouping "Year", sort "Runs" in descending order

vnuocmsft_1-1703665601091.png

 

Top_Rank_Batsman = RANKX(FILTER(ALL('Table'),[Year]=MAX('Table'[Year])),CALCULATE(SUM('Table'[Runs])),,DESC,Dense)

 

vnuocmsft_2-1703665623487.png

 

Filter the data in "Filters" and select the record with a ranking of "1".

vnuocmsft_3-1703665642799.png

 

Here is the result

vnuocmsft_4-1703665669771.png

 

Best Regards,

Nono Chen

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

3 REPLIES 3
Anonymous
Not applicable

Hi @Ebrahim1123 

 

For questions where you want to find the batsman who scores the most points per year via the rank function, we recommend that you use “rankx”, as “rankx” sorts the same values in the column to the same level. This avoids over-sieving or missing data.

 

we have the following solutions:

 

Here's some dummy data

vnuocmsft_0-1703665576404.png

 

Create a measure, after grouping "Year", sort "Runs" in descending order

vnuocmsft_1-1703665601091.png

 

Top_Rank_Batsman = RANKX(FILTER(ALL('Table'),[Year]=MAX('Table'[Year])),CALCULATE(SUM('Table'[Runs])),,DESC,Dense)

 

vnuocmsft_2-1703665623487.png

 

Filter the data in "Filters" and select the record with a ranking of "1".

vnuocmsft_3-1703665642799.png

 

Here is the result

vnuocmsft_4-1703665669771.png

 

Best Regards,

Nono Chen

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

 

 

Fowmy
Super User
Super User

@Ebrahim1123 

If you need to show the top batsman by year on a visual, a masure will be useful as well. Add the Year colum to a table visual and add the following meaure:

Rank Top = 
MAXX(
    TOPN( 1  , VALUES( Rankbyyear[batsman] ) , CALCULATE(SUM( Rankbyyear[runs] )) , DESC ),
    [batsman] 
)

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Nithinr
Resolver III
Resolver III

create a calculated column :

col = RANKX(FILTER(table,table[year]=EARLIER(table[year])),table[Runs])

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.