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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ADSL
Post Prodigy
Post Prodigy

Calculate time spent by session

Hi BI Community Team,

 

With screenshot below, we're looking for the time spent:

1. By session - early morning, morning, lunch, afternoon, evening & late evening.

2. Total time spent

 

sample file - https://drive.google.com/drive/folders/1EsiFHTEmDmDu4VJ1DCvXqjLPEf6ya_bk?usp=drive_link 

 

2023-07-22_19-34-04.png

Any suggestion/advise?

 

Thanks and Regards,

2 REPLIES 2
jdbuchanan71
Super User
Super User

The number above is the time spent between the earliest log_in and the latest log_out which may not be what you are looking for.  It looks like each row is a separate instance so we can calcualte the time in seconds for each row with a calculated column.

Time Spent Seconds = DATEDIFF(VISIT_SUMM[TIME_IN],VISIT_SUMM[TIME_OUT],SECOND)

Then a measure to sum the time in seconds.

Duration Seconds = SUM ( [Time Spent Seconds] )

Then the duration measure becomes this.

Time Spent = 
VAR _Seconds = [Duration Seconds]
VAR _Minutes = INT ( DIVIDE ( _Seconds, 60 ) )
VAR _RemainingSeconds = MOD ( _Seconds, 60 )
VAR _Hours = INT ( DIVIDE ( _Minutes, 60 ) )
VAR _RemainingMinutes = MOD ( _Minutes, 60 )

RETURN
IF  ( NOT ISBLANK ( _Seconds ), 
    SWITCH ( TRUE(),
    _Seconds < 60, FORMAT ( _RemainingSeconds, "0" ),
    _Seconds < 3600,  FORMAT ( _RemainingMinutes, "0" ) & ":" & 
                    FORMAT ( _RemainingSeconds, "00" ),
    FORMAT ( _Hours, "#,#" ) & ":" & 
    FORMAT ( _RemainingMinutes, "00" ) & ":" & 
    FORMAT ( _RemainingSeconds, "00" )
    )
)

One good thing about doing it this way is you can summarize it at whatever level you want and the amounts still sum:

jdbuchanan71_2-1690033807691.png

 

 

jdbuchanan71
Super User
Super User

In your visual, your End Time field should be looking at the Latest 'VISIT_SUMM'[Log_Out] I think.

jdbuchanan71_0-1690033178885.png

Then a measure like this will give us the time format duration.

Time Spent = 
VAR _Start = MIN ( VISIT_SUMM[TIME_IN] )
VAR _End = MAX ( VISIT_SUMM[TIME_OUT] )
VAR _Seconds = DATEDIFF ( _Start, _End, SECOND )
VAR _Minutes = INT ( DIVIDE ( _Seconds, 60 ) )
VAR _RemainingSeconds = MOD ( _Seconds, 60 )
VAR _Hours = INT ( DIVIDE ( _Minutes, 60 ) )
VAR _RemainingMinutes = MOD ( _Minutes, 60 )

RETURN
IF  ( NOT ISBLANK ( _Seconds ), 
    SWITCH ( TRUE(),
    _Seconds < 60, FORMAT ( _RemainingSeconds, "0" ),
    _Seconds < 3600,  FORMAT ( _RemainingMinutes, "0" ) & ":" & 
                    FORMAT ( _RemainingSeconds, "00" ),
    FORMAT ( _Hours, "#,#" ) & ":" & 
    FORMAT ( _RemainingMinutes, "00" ) & ":" & 
    FORMAT ( _RemainingSeconds, "00" )
    )
)

jdbuchanan71_1-1690033312339.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.