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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Jamesfindog
Frequent Visitor

RANK with PARTITION BY Like SQL

Hi,

 

I am looking to use a DAX formula, similar to the RANK with Partition By window function within SQL.

 

My desired result is the below:


IDDateRank
101-Jan-211
101-Jan-211
102-Jan-212
103-Jan-213
201-Jan-211
202-Jan-212
301-Jan-001
401-Jan-001

 

This DAX is not working, I am receiving all 1 values as below:

Ranker =
RANKX(
    ALL(Table[ID]), Table[Date])
 
 
IDDateRank
101-Jan-211
101-Jan-211
102-Jan-211
103-Jan-211
201-Jan-211
202-Jan-211
301-Jan-001
401-Jan-001
 
 Thanks for your help.
2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

The newer RANK function should make this easier than it used to be.

 

Try this:

RANK (
    DENSE,
    ORDERBY ( 'Table'[Date], ASC ),
    PARTITIONBY ( 'Table'[ID] )
)

View solution in original post

Calculate column on Table, where you add a column to calculate the year

 

Year = YEAR ( Tabella[Date] )

 

Finale Column

RANK ( DENSE, ORDERBY( Tabella[Date] ), DEFAULT, PARTITIONBY( Tabella[YEAR]))
 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

View solution in original post

8 REPLIES 8
AlexisOlson
Super User
Super User

The newer RANK function should make this easier than it used to be.

 

Try this:

RANK (
    DENSE,
    ORDERBY ( 'Table'[Date], ASC ),
    PARTITIONBY ( 'Table'[ID] )
)

Thanks mate, perfect.

MFelix
Super User
Super User

Hi @Jamesfindog ,

 

Check this post.

 

https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-RANKX-with-Partition-By/m-p/2389...


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Same issue, utilised exactly, still receiving all 1 values.

rn =
VAR CurrentDate =
    SELECTEDVALUE ( Table[Date] )
VAR RankingTable =
    CALCULATETABLE (
        SUMMARIZE ( Table, Table[Date] ),
        ALLSELECTED (), -- filter context of visual
        VALUES ( Table[ID]) -- retain current Category filter
    )
RETURN
    RANKX (
        RankingTable,
        Table[Date],
        CurrentDate,
        ASC
    )
Jamesfindog
Frequent Visitor

Apologies, I desire this to be ranked by earliest date.

I do not understand the following

 

1  are yo ulooking for a column to add to the table or to a measure?

 

2 your desred result is confusing

 

IDDateRank
101-Jan-211
101-Jan-211
102-Jan-212
103-Jan-213
201-Jan-211
202-Jan-212
301-Jan-001
401-Jan-001

 

do you want the rank within a year?

 

Thanks

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Hi mate,

 

A new column, which ranks the dates grouped by each ID.

 

The actual date value is irrelevant, I just want the earliest to be 1 for each ID, and the second 2, and so forth.

Calculate column on Table, where you add a column to calculate the year

 

Year = YEAR ( Tabella[Date] )

 

Finale Column

RANK ( DENSE, ORDERBY( Tabella[Date] ), DEFAULT, PARTITIONBY( Tabella[YEAR]))
 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors