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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.