Forum Discussion
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
| UserName | TimeStamp | Status |
| abc | 2025-03-20 01:33 | Login |
| abc | 2025-03-20 06:11 | Logoff |
| abc | 2025-03-20 06:23 | Login |
| abc | 2025-03-20 09:48 | Logoff |
| abc | 2025-03-20 22:07 | Login |
| abc | 2025-03-20 22:33 | Logoff |
| abc | 2025-03-20 22:34 | Login |
| abc | 2025-03-21 02:55 | Logoff |
| abc | 2025-03-21 02:56 | Login |
| abc | 2025-03-21 10:04 | Logoff |
| abc | 2025-03-21 22:08 | Login |
| abc | 2025-03-22 09:46 | Logoff |
| abc | 2025-03-22 22:11 | Login |
| abc | 2025-03-23 09:48 | Logoff |
| def | 2025-03-20 08:33 | Login |
| def | 2025-03-21 09:33 | Logoff |
| def | 2025-03-22 09:34 | Login |
| def | 2025-04-01 08:33 | Login |
| def | 2025-04-02 16:33 | Logoff |
My expected result for user abc
| Login | Logoff |
| 2025-03-20 22:07 | 2025-03-21 10:04 |
| 2025-03-21 22:08 | 2025-03-23 09:48 |
Thank you in advance
18 Replies
- SamanthaPuaXYHelper II
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! ๐- Yacine2025Frequent Visitor
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
- ryan_mayuSuper User
why we don't calculate the time for the first 5 rows?
- Yacine2025Frequent 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_mayuSuper User
still not clear about the logic. could you pls update the sample data and expected output?