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
YessikaLp
Frequent Visitor

How to group with times, Hours and minutes. HELP PLEASE!!!!

Hello there, 

I have been trying to come up with a formula that will calculate how many incidents were recorded in total per day. The following info is what I have: 

I have been manually entering the Incident # (but I am sure that power BI can do this for me :)).

It is considered as 1 incidents all recordings between 1 - 2minutes apart. For example truck#9403 recorded 2 counts (less than 1min apart), those two counts are considered as 1 incident.

YessikaLp_0-1664483132518.png

 

If you can help me with this, I will really appreciate it. 

 

Thanks!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @YessikaLp ,

You can create two calculated columns as below to get it, please find the details in the attachment.

Time Diff>1 =
VAR _pretime =
    CALCULATE (
        MAX ( 'Table'[Column1] ),
        FILTER (
            'Table',
            'Table'[Day] = EARLIER ( 'Table'[Day] )
                && 'Table'[Column1] < EARLIER ( 'Table'[Column1] )
        )
    )
VAR _timediff =
    DIVIDE ( DATEDIFF ( _pretime, 'Table'[Column1], SECOND ), 60, 0 )
RETURN
    IF ( ISBLANK ( _pretime ), 1, IF ( _timediff >= 1, 1, 0 ) )
Incident # =
CALCULATE (
    SUM ( 'Table'[Time Diff>1] ),
    FILTER ( 'Table', 'Table'[Column1] <= EARLIER ( 'Table'[Column1] ) )
)

yingyinr_0-1664507442836.png

Best Regards

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @YessikaLp ,

You can create two calculated columns as below to get it, please find the details in the attachment.

Time Diff>1 =
VAR _pretime =
    CALCULATE (
        MAX ( 'Table'[Column1] ),
        FILTER (
            'Table',
            'Table'[Day] = EARLIER ( 'Table'[Day] )
                && 'Table'[Column1] < EARLIER ( 'Table'[Column1] )
        )
    )
VAR _timediff =
    DIVIDE ( DATEDIFF ( _pretime, 'Table'[Column1], SECOND ), 60, 0 )
RETURN
    IF ( ISBLANK ( _pretime ), 1, IF ( _timediff >= 1, 1, 0 ) )
Incident # =
CALCULATE (
    SUM ( 'Table'[Time Diff>1] ),
    FILTER ( 'Table', 'Table'[Column1] <= EARLIER ( 'Table'[Column1] ) )
)

yingyinr_0-1664507442836.png

Best Regards

Thank youfor the answer!! very very helpul, but... I have another question.

 

The following example Truck #1 had an incident at 9:03:50 and less than 1 min another truck had another incident. What can I add to the formula so that identifies that it is another truck which is having an incident and separate the incidents because the formula I have is considering but truck as 1 incident.

YessikaLp_0-1664917378098.png

Thank you in advance for the help!!!

Anonymous
Not applicable

Hi @YessikaLp ,

I updated the sample pbix file(see the attachement), please check if that is what you want.

yingyinr_1-1665021198730.png

Best Regards

amitchandak
Super User
Super User

@YessikaLp , Create a new flag column

 

=

var _max = maxx(filter(Table, [Trucks] = earlier([Truck]) && [Date] = earlier([Date]) && [Time] < earlier([Time]) ), [Time])

return

Switch(True(),

isblank(_max) , blank() ,

datediff(_max, [Time], minute) <2, blank() ,

[Time]

)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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