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

How much time did an user logged in?

Hello guys,

 

Supposed I have the following data of users, each time they logged in and logged out:

User    LoggingType   Date 

1         In                     2018-10-05 13:18:26.900

1         Out                  2018-10-05 13:18:54.353

1         In                     2018-10-05 13:19:23.637

1         Out                  2018-10-05 13:20:03.887

2         In                     2018-10-05 13:21:25.887

2         Out                  2018-10-05 13:22:01.247

3         In                     2018-10-10 18:24:33.867

3         Out                  2018-10-10 18:25:35.443

 

How do I create another column illustrating how long an user was logged in for a session? For example, here's what I wish to see:

User    LoggingType   Date                                      Duration

1         In                     2018-10-05 13:18:26.900      

1         Out                  2018-10-05 13:18:54.353      2018-10-05 13:18:54.353 - 2018-10-05 13:18:26.900

1         In                     2018-10-05 13:19:23.637

1         Out                  2018-10-05 13:20:03.887      2018-10-05 13:20:03.887 - 2018-10-05 13:19:23.637

2         In                     2018-10-05 13:21:25.887

2         Out                  2018-10-05 13:22:01.247      2018-10-05 13:22:01.247 - 2018-10-05 13:21:25.887

3         In                     2018-10-10 18:24:33.867

3         Out                  2018-10-10 18:25:35.443      2018-10-10 18:25:35.443 - 2018-10-10 18:24:33.867

1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

Hi @Anonymous ,

Based on my test, you could refer to below steps:

Add index for your data in query editor:

1.PNG

Apply it and create below formula:

Column = var a=[Index]-1
return CALCULATE(MAX(Table1[Date]),FILTER('Table1','Table1'[Index]=a))

Result:

1.PNG

Now you could use the [Date] column to minus the [Column].

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-danhe-msft
Employee
Employee

Hi @Anonymous ,

Based on my test, you could refer to below steps:

Add index for your data in query editor:

1.PNG

Apply it and create below formula:

Column = var a=[Index]-1
return CALCULATE(MAX(Table1[Date]),FILTER('Table1','Table1'[Index]=a))

Result:

1.PNG

Now you could use the [Date] column to minus the [Column].

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks this is what I was looking for

GilbertQ
Super User
Super User

Hi there

What you would need to do, is to create an Index column and then you can create a calculated column which will then put in the data on the corresponding row

This answer explains how to achieve this: https://community.powerbi.com/t5/Desktop/How-to-get-previous-row-value-for-text-column/td-p/312560




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

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.

Top Solution Authors
Top Kudoed Authors