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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonomous_user
Frequent Visitor

How to rank categorical data based on time factor

Hello, I have a data frame which has 3 variables i.e. Id, Event and time for each id there can be multiple event happening and for each event date time factor has been added to find out at what time which event happen. My data frame looks like this as below.

 

IdEvent              Time(DD/MM/YYYY HH:MM:SS)Output
1event1              4/20/2022 1:09:47 AM1
1event2              4/20/2022 1:12:23 AM2
1event3              4/20/2022 1:13:35 AM3
1event4              4/20/2022 1:13:36 AM4
1event5              4/20/2022 1:13:37 AM5
1event4              4/20/2022 1:15:17 AM4
1event3              4/20/2022 5:56:35 AM3
1event5              4/20/2022 5:56:35 AM5
2event1              4/26/2022 11:19:00 AM1
2event2              4/26/2022 11:20:05 AM2
2event3              4/26/2022 11:20:46 AM3
2event5              4/26/2022 11:20:50 AM4

Added blank column so that there could be space between event and Time column(Ignore)

 

The difference in event can be seconds, minute or hours or days.

 

My Aim is to based on my Id column I need to add rank order to the events based on Date time factor. So for each Id rank order should starts with 1. 

 

And if the event is repetated like for example consider event4 for Id 1 it has been repetated twice so it should pick first category value assigned to it.

 

Any help would be appreciated 

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi,

Thank you for your message.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1683459424717.png

 

Expected result CC =
VAR _summarizetable =
    GROUPBY (
        Data,
        Data[Id],
        Data[Event],
        "@time_earliest", MINX ( CURRENTGROUP (), Data[Time(DD/MM/YYYY HH:MM:SS)] )
    )
RETURN
    RANK (
        SKIP,
        _summarizetable,
        ORDERBY ( [@time_earliest], ASC ),
        PARTITIONBY ( Data[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.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

HI,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1683445823889.png

 

Expected result CC =
RANK (
    SKIP,
    SUMMARIZE ( Data, Data[Id], Data[Event], Data[Time(DD/MM/YYYY HH:MM:SS)] ),
    ORDERBY ( Data[Time(DD/MM/YYYY HH:MM:SS)], ASC, Data[Event], ASC ),
    PARTITIONBY ( Data[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.

Hi, Sorry missed 1 part my Expected Output should be same as output column in the table which I have added above. 

Logic behind the output is "if the event is repetated like for example consider event4 for Id 1 it has been repetated twice so it should pick first category value assigned to it."

Hi,

Thank you for your message.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1683459424717.png

 

Expected result CC =
VAR _summarizetable =
    GROUPBY (
        Data,
        Data[Id],
        Data[Event],
        "@time_earliest", MINX ( CURRENTGROUP (), Data[Time(DD/MM/YYYY HH:MM:SS)] )
    )
RETURN
    RANK (
        SKIP,
        _summarizetable,
        ORDERBY ( [@time_earliest], ASC ),
        PARTITIONBY ( Data[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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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