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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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 ) )

Regards
Zubair

Please try my custom visuals

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 ) )

Regards
Zubair

Please try my custom visuals
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 ) )

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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