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
Anonymous
Not applicable

Need help to Calculate Time duration

Hello All,

 

 

I have swipe card details table as below

 

1.PNG

 

Here i would like to calculate the time duration from In and out each time.

 

Here in above image we need to get the time duration from 1st I01 to 1st O01 like wise for every In and Out.

But at last I01 theres no Out, so here from that In time to current time calculate the time duration.

 

 

How can i calculate the time duration.

 

Any suggestion please

 

Mohan V

1 ACCEPTED SOLUTION

@Anonymous

 

Try this

 

=
VAR OutTime =
    CALCULATE (
        MIN ( TableName[Time] ),
        FILTER (
            TableName,
            TableName[Time] > EARLIER ( TableName[Time] )
                && TableName[Employee Name] = EARLIER ( TableName[Employee Name] )
                && TableName[In/Out] = "O01"
        )
    )
VAR Endtime =
    IF ( ISBLANK ( OutTime ), NOW (), OutTime )
RETURN
    IF ( TableName[In/Out] = "I01", DATEDIFF ( TableName[Time], EndTime, MINUTE ) )

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

Try this column

 

=
VAR OutTime =
    CALCULATE (
        MIN ( TableName[Time] ),
        FILTER (
            TableName,
            TableName[Time] > EARLIER ( TableName[Time] )
                && TableName[In/Out] = "O01"
        )
    )
VAR Endtime =
    IF ( ISBLANK ( OutTime ), NOW (), OutTime )
RETURN
    IF ( TableName[In/Out] = "I01", DATEDIFF ( TableName[Time], EndTime, MINUTE ) )
Anonymous
Not applicable

Hi @Zubair_Muhammad 

 

I have tried what you have suggested.

 

but it is not giving me the right output

1.PNG

 

Can you please help me to get this done..

It will help me a lot.

 

Thank you.

Mohan V

@Anonymous

 

Try this

 

=
VAR OutTime =
    CALCULATE (
        MIN ( TableName[Time] ),
        FILTER (
            TableName,
            TableName[Time] > EARLIER ( TableName[Time] )
                && TableName[Employee Name] = EARLIER ( TableName[Employee Name] )
                && TableName[In/Out] = "O01"
        )
    )
VAR Endtime =
    IF ( ISBLANK ( OutTime ), NOW (), OutTime )
RETURN
    IF ( TableName[In/Out] = "I01", DATEDIFF ( TableName[Time], EndTime, MINUTE ) )

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