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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jimminy
Frequent Visitor

Rank groups within unique IDs and by date

Hi community!

 

I have the current example data:

ticket_idstart_date_time_localService Team
1123/05/2023 11.42Team 1
1123/05/2023 11.46Team 1
1123/05/2023 11.47Team 2
1123/05/2023 11.47Team 3
2224/05/2023 15.16Team 5
2225/05/2023 14.01Team 5
2207/06/2023 05.19Team 2
2203/07/2023 15.59Team 2
2204/07/2023 12.25Team 4
2204/07/2023 12.25Team 1
2204/07/2023 14.47Team 1

 

And am trying to create a ranked column with the below output:

ticket_idstart_date_time_localService TeamRank
1123/05/2023 11.42Team 11
1123/05/2023 11.46Team 11
1123/05/2023 11.47Team 22
1123/05/2023 11.47Team 33
2224/05/2023 15.16Team 51
2225/05/2023 14.01Team 51
2207/06/2023 05.19Team 22
2203/07/2023 15.59Team 22
2204/07/2023 12.25Team 43
2204/07/2023 12.25Team 14
2204/07/2023 14.47Team 14

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jimminy ,

 

Here's my solution.

1.Create an index column in Power Query.

vstephenmsft_0-1689759493325.png

vstephenmsft_1-1689759501152.png

 

2.Go back to Power BI Desktop and create two calculated columns.

Column = 
IF(
    'Table'[Index]=
MINX(
    FILTER(ALL('Table'),'Table'[ticket_id]=EARLIER('Table'[ticket_id])&&'Table'[Service Team]=EARLIER('Table'[Service Team])),[Index]),1,0)
Final Rank = 
SUMX(
    FILTER(ALL('Table'),
    'Table'[ticket_id]=EARLIER('Table'[ticket_id])&&'Table'[Index]<=EARLIER('Table'[Index])),[Column])

vstephenmsft_2-1689759555995.png

 

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi @jimminy ,

 

Here's my solution.

1.Create an index column in Power Query.

vstephenmsft_0-1689759493325.png

vstephenmsft_1-1689759501152.png

 

2.Go back to Power BI Desktop and create two calculated columns.

Column = 
IF(
    'Table'[Index]=
MINX(
    FILTER(ALL('Table'),'Table'[ticket_id]=EARLIER('Table'[ticket_id])&&'Table'[Service Team]=EARLIER('Table'[Service Team])),[Index]),1,0)
Final Rank = 
SUMX(
    FILTER(ALL('Table'),
    'Table'[ticket_id]=EARLIER('Table'[ticket_id])&&'Table'[Index]<=EARLIER('Table'[Index])),[Column])

vstephenmsft_2-1689759555995.png

 

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

Hi, Thanks for the solution. However I run into an issue when the team repeats e.g. if it returns to team 1 after going to team 2. Do you know how to solve this?

jimminy
Frequent Visitor

Thanks for taking the time, and this solution is what I'm looking for. Although when I use the above code I don't get exactly the right result. For example the result for a ticket using this code is shown below:

ticket_id
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
start_date_time_local
23/05/2023 11.42.58
23/05/2023 11.46.28
23/05/2023 11.47.14
23/05/2023 11.47.45
24/05/2023 14.46.47
24/05/2023 15.16.44
24/05/2023 15.16.56
25/05/2023 14.01.43
07/06/2023 05.19.03
03/07/2023 15.59.57
04/07/2023 12.25.03
04/07/2023 12.25.33
04/07/2023 14.47.46
service_and_support_team_id
Team1
Team1
Team1
Team2
Team2
 
Team2
Team2
Team2
Team1
Team1
Team2
Team2
Team Rank CC
2
2
2
3
3
1
3
3
3
2
2
3
3

 

Where as the result I am looking for would be this:

ticket_id
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
7777777
start_date_time_local
23/05/2023 11.42.58
23/05/2023 11.46.28
23/05/2023 11.47.14
23/05/2023 11.47.45
24/05/2023 14.46.47
24/05/2023 15.16.44
24/05/2023 15.16.56
25/05/2023 14.01.43
07/06/2023 05.19.03
03/07/2023 15.59.57
04/07/2023 12.25.03
04/07/2023 12.25.33
04/07/2023 14.47.46
service_and_support_team_id
Team1
Team1
Team1
Team2
Team2
 
Team2
Team2
Team2
Team1
Team1
Team2
Team2
Team Rank CC
1
1
1
2
2
3
4
4
4
5
5
6
6
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1688652423897.png

 

 

Team Rank CC =
VAR _t =
    GROUPBY (
        Data,
        Data[ticket_id],
        Data[Service Team],
        "@startdatetime", MAXX ( CURRENTGROUP (), Data[start_date_time_local] )
    )
RETURN
    RANK (
        SKIP,
        _t,
        ORDERBY ( [@startdatetime], ASC, Data[Service Team], ASC ),
        PARTITIONBY ( Data[ticket_id] )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.