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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Calculated column for rank within group

Hi,

I have data including a unique session id, a timestamp for the different events within that session and their names. I would like to create a column that shows the rank of each event within the session, as shown below.

Session_IDTimestampNameRank
122.05.2023 18:00a1
122.05.2023 18:10b2
222.05.2023 18:05b1
222.05.2023 18:07a2

I've tried a couple of different things, but the closest I've come is with this (Overview being the table name):

Rank within Session =
RANKX(
    FILTER(
        'Overview',
        'Overview'[Session_ID]=EARLIER(Overview[Session_ID])
    ),
    'Overview'[Timestamp]
    )
which however gives the overall rank, disregarding session_id.
 
Any help would be greatly appreciated!
1 ACCEPTED SOLUTION
NaveenGandhi
Super User
Super User

Hello @Anonymous 

 

Use the below Measure to populate the required result.

 

Rank Column =
RANKX(
    FILTER(
        rankkx,
        rankkx[Session_ID] = EARLIER(rankkx[Session_ID]) &&
        (rankkx[Timestamp] < EARLIER(rankkx[Timestamp]) ||
        rankkx[Name] < EARLIER(rankkx[Name]))
    ),
    rankkx[Timestamp],
    ,
    ASC,
    Dense
)
NaveenGandhi_0-1684773498376.png

 

let me know if this helps.
 
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks a lot, @NaveenGandhi, this seems to work 🙂

NaveenGandhi
Super User
Super User

Hello @Anonymous 

 

Use the below Measure to populate the required result.

 

Rank Column =
RANKX(
    FILTER(
        rankkx,
        rankkx[Session_ID] = EARLIER(rankkx[Session_ID]) &&
        (rankkx[Timestamp] < EARLIER(rankkx[Timestamp]) ||
        rankkx[Name] < EARLIER(rankkx[Name]))
    ),
    rankkx[Timestamp],
    ,
    ASC,
    Dense
)
NaveenGandhi_0-1684773498376.png

 

let me know if this helps.
 
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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