Forum Discussion

Yacine2025's avatar
Yacine2025
Frequent Visitor
1 year ago
Solved

Need help

Hi everyone

I'm New in power bi and i need help to resolve this case. I want to calculate session duration between login and logout for each user per login date knowing that status can contains multiple login logout and session can cross midnight.

 

Here is my data

UserNameTimeStampStatus
abc2025-03-20 01:33Login
abc2025-03-20 06:11Logoff
abc2025-03-20 06:23Login
abc2025-03-20 09:48Logoff
abc2025-03-20 22:07Login
abc2025-03-20 22:33Logoff
abc2025-03-20 22:34Login
abc2025-03-21 02:55Logoff
abc2025-03-21 02:56Login
abc2025-03-21 10:04Logoff
abc2025-03-21 22:08Login
abc2025-03-22 09:46Logoff
abc2025-03-22 22:11Login
abc2025-03-23 09:48Logoff
def2025-03-20 08:33Login
def2025-03-21 09:33Logoff
def2025-03-22 09:34Login
def2025-04-01 08:33Login
def2025-04-02 16:33Logoff

 

 

My expected result for user abc

LoginLogoff
2025-03-20 22:072025-03-21 10:04
2025-03-21 22:082025-03-23 09:48
  

 

 

Thank you in advance

18 Replies

  • Hi Yacine2025 

    You could filter to get a table with just Log off details and a table with just Login in details. Sort them according to timestamp, index them and do a merge with the Index to get the respective Log off details.

     

    This is assuming the data is clean and each log in will have a respective log off, vice versa.

    Do give a kudos if this helps! ๐Ÿ™‚

    • Yacine2025's avatar
      Yacine2025
      Frequent Visitor

      Hi SamanthaPuaXY 

      Thanks for your reply, i have a multiple login logout per session so for the moment its difficult to pair login logout and some sessions of users cross midnight.

       

      Thanks

    • Yacine2025's avatar
      Yacine2025
      Frequent Visitor

      Hi ryan_mayu 

      I just ignore them in my post because the login is in the Last day but yes i want to do the same calculate for every user every day 

      Thanks for your Quick reply

      • ryan_mayu's avatar
        ryan_mayu
        Super User

        still not clear about the logic. could you pls update the sample data and expected output?