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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors